Lab 10 Menu Code
จุดประสงค์การเรียนรู้
สามารถเขียนCodeภาษาCในArduino IDEสร้างMenu Codeได้
สาระการเรียนรู้
การสร้างMenu Code เป็นการลดปริมาณจำนวนครั้ังของการUpload เมื่อต้องการเรียกใช้งานหลายๆฟังก์ชันผ่านMenu ในการUpload Codeเพียงครั้งเดียว ตัวอย่างการใช้ Menu Code อาจจะใช้งานในEmbeded system ดังนี้
Menu 1 เล่นเสียงดนตรี 1 ครั้ง
Menu 2 เล่นเสียงดนตรี 2 ครั้ง
Menu 3 เล่นเสียงดนตรี 3 ครั้ง
Menu 4 เล่นเสียงดนตรี 4 ครั้ง เป็นต้น
2. คำสั่งการใช้งาน
รูปแบบการใช้งานคำสั่งในภาษาซีของArduino IDEในเนื้อหานี้ จะใช้คำสั่งดังต่อไปนี้
วัสดุอุปกรณ์
1. ไมโครสวิตซ์ ชนิดกดติดปล่อยดับ จำนวน 1 ตัว
2. ตัวต้านทาน 10 กิโลโอห์ม จำนวน 1 ตัว
3. บอร์ด ESP32 Devkit V.1 จำนวน 1 บอร์ด
4. สายMicro USB จำนวน 1 เส้น
5. Breadboard
6. สายแพร Male-Male
7. หลอด LED จำนวน 3 หลอด
8. ตัวต้านทาน 220 โอห์ม จำนวน 3 ตัว
9. ตัวต้านทานปรับค่าได้ Potentiometer จำนวน 1 ตัว
10. ลำโพงBuzzer จำนวน 1 อัน
11. จอแสดงผล OLED I2C จำนวน 1 อัน
12. Servo Motor จำนวน 1 ตัว
13. โมดูลMb 102 Breadboard จำนวน 1 ตัว
14. Adaptor 9Vdc จำนวน 1 ตัว
15. ไดซ์มอเตอร์ TB6612 FNG จำนวน 1 ตัว
16. มอเตอร์กระแสตรง จำนวน 2 ตัว
วิธีทำการทดลอง
1. หากทำการทดลอง Lab1-Lab10 แล้ว ไม่จำเป็นต้องต่ออะไรเพิ่มเติมอีก
2. ทำการCopy Codeด้านล่างก่อนUpload code Arduino IDE ลงไปใบนบอร์ด ESP32 Devkit v1
ควรเลือกที่Tool -> Board -> ESP32 Arduino ->ESP32 Dev Module (ดังภาพประกอบด้านล่าง)
Menu Code v1
#include <ESP32Servo.h>
///////// ผนวกไลบรารี่ ////////////
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 OLED(-1);
///////////ตั้งค่าปุ่มกด///////////////////
int button = 27; /// กำหนดปุ่มกดสวิตซ์ขา 27
int snd = 18;
/////////////////////////////////////////////////////////////////////
void setup() {
OLED.begin(SSD1306_SWITCHCAPVCC,0x3C); // กำหนดแอดเดรสของพอร์ตจอเป็น 0x3C (for the 128x64)
pinMode(button, INPUT); // ตั้งค่าขา button เป็น INPUT
}
void loop(){
int sw = digitalRead(button); // ให้ sw อ่านค่า digital จากพอร์ต 2(button)
int nob = analogRead(35); // ให้ nob อ่านค่าพอร์ตAnalog 35
int menu = map(nob,0,4095,0,12); // เทียบอัตราส่วนของพอร์ตAnalog 35 จาก 0-4095เพื่อทำเป็นเมนู 0-12
OLED.clearDisplay(); // ล้างค่าหน้าจอ
OLED.setTextColor(WHITE,BLACK); //สีอักษรเป็นสีขาว ,พื้นหลังดำ
OLED.setCursor(0, 0); // เซตตำแหน่ง 0,0
OLED.setTextSize(2); // เซตขนาดอักษรมีขนาดเป็น 2
OLED.println("ROBOT MENU"); // พิมพ์คำว่า ROBOT MENU
OLED.setTextSize(2); // เซตขนาดอักษรมีขนาดเป็น 2
OLED.print(" "); // วรรค
OLED.println(menu); // แสดงค่า Menu ที่ได้จากการ map nob ให้เหลือ 0-12
OLED.setTextSize(1); // เซตขนาดอักษรมีขนาดเป็น 2
OLED.println(" KLS ROBOT CENTER"); // พิมพ์คำว่า KLS ROBOT CENTER
OLED.print(" "); // วรรค
OLED.print(nob); // แสดงค่าที่อ่านได้จาก nob หรือ Analog7
OLED.println(" www.kls.ac.th"); // พิมพ์คำว่า www.kls.ac.th
OLED.display();
if ((sw == 0)and(menu==0)) { OLED.clearDisplay();OLED.display();}
if ((sw == 0)and(menu==1)) {t();} //เมนู 1 เสียงดัง 1 ครั้ง
if ((sw == 0)and(menu==2)) {t();t();} //เมนู 2 เสียงดัง 2 ครั้ง
if ((sw == 0)and(menu==3)) {t();t();t();} //เมนู 3 เสียงดัง 3 ครั้ง
if ((sw == 0)and(menu==4)) {t();t();t();t();} //เมนู 4 เสียงดัง 4 ครั้ง
if ((sw == 0)and(menu==5)) {t();t();t();t();t();} //เมนู 5 เสียงดัง 5 ครั้ง
if ((sw == 0)and(menu==6)) {t();t();t();t();t();t();} //เมนู 6 เสียงดัง 6 ครั้ง
if ((sw == 0)and(menu==7)) {t();t();t();t();t();t();t();} //เมนู 7 เสียงดัง 7 ครั้ง
if ((sw == 0)and(menu==8)) {t();t();t();t();t();t();t();t();} //เมนู 8 เสียงดัง 8 ครั้ง
if ((sw == 0)and(menu==9)) {t();t();t();t();t();t();t();t();t();} //เมนู 9 เสียงดัง 9 ครั้ง
if ((sw == 0)and(menu==10)) {t();t();t();t();t();t();t();t();t();t();} //เมนู 10 เสียงดัง 10 ครั้ง
if ((sw == 0)and(menu==11)) {t();t();t();t();t();t();t();t();t();t();t();} //เมนู 11 เสียงดัง 11 ครั้ง
if ((sw == 0)and(menu==12)) {t();t();t();t();t();t();t();t();t();t();t();t();} //เมนู 12 เสียงดัง 12 ครั้ง
delay(100);
}
void t() // ฟังก์ชันเสียงดังที่พอร์ต 3
{tone(snd,1000,100);delay(300); }
3.หลังจากนั้นให้เข้ามาที่ Tool ->Port แล้วเลือกพอร์ตC om portที่เชื่อมกับUSB ดังรูปข้างล่าง
** กรณีใช้งานใน Ubuntu พอร์ตที่ใช้อาจจะเป็นพอร์ตttyUSB0 ซึ่งจะต้องเลือกเป็นพอร์ตชื่อนี้แทนCom port และก่อนกดUpload ให้ทำการเปิดTerminal โดยเข้าไปที่desktop คลิกขวาตรงพื้นที่ว่าง แล้วเลือก Open Terminal หลังจากนั้นให้พิมพ์ข้อความในTerminalดังนี้เพื่อทำการเปิดพอร์ตUSB : sudo chmod 666 /dev/ttyUSB0 หลังจากนั้นให้กดEnter และทำการกรอกรหัสผ่านของเครื่องพร้อมกับกดปุ่มEnterอีกครั้ง หลังจากนั้นก็Upload codeในArduino IDE
4.ทำการกดปุ่มUpload ที่เป็นรูปหัวลูกษร หรือจะกด Ctrl+u ที่คีย์บอร์ดเพื่อทำการUploadโปรแกรมไปที่บอร์ดESP32 ดังรูปข้างล่าง
5. หลังจากที่Uploadโปรแกรมแล้ว ให้ทำการหมุดK-nob แล้วสังเกตMenuพร้อมหมายเลขที่เกิดขึ้น หากต้องการเล่นเสียงดนตรีให้กดที่ไมโครสวิตซ์เพื่อเริ่มการทำงานเล่นเสียงดนตรีจำนวนหมายเลขในMenu
ตอนที่ 2 การใช้งานMenu CODE ร่วมกับฟังก์ชันอื่นๆ
ในการทดลองตอนที่2 นี้เป็นแนวทางในการเขียนCode Menuใช้งานร่วมกับคำสั่งควบคุมDC Motor ,Servo Motor และคำสั่งควบคุมความถี่เสียง สามารถUpload Codeตัวอย่างและลองเรียกใช้งานMenuได้เลย
Menu code v2
//////// ผนวกไลบรารี่ ////////////
#include <ESP32Servo.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_ADS1015.h>
#include <MechaQMC5883.h>
Adafruit_SSD1306 OLED(-1);
Adafruit_ADS1115 ads(0x48);
MechaQMC5883 qmc;
//////////Sound buzzer์///////////
int snd = 18;
//////// set io ///////////////////
int button = 27; ///button
int k_nob = 35 ; // K-nob
int ss1 = 32; // servo ch1
int ss2 = 33; // servo ch2
int ss3 = 23; // servo ch3
Servo sv1;
Servo sv2;
Servo sv3;
///////////////////////////////////////////
////////// variable motor port/////////////
#define DR1 16
#define DR2 17
#define PWMR 4
/////////////////////////////////
#define DL1 2
#define DL2 15
#define PWML 13
/////////////////////////////////
void setup() {
OLED.begin(SSD1306_SWITCHCAPVCC, 0x3C); // address i2c 0x3C (for the 128x64)
pinMode(button , INPUT);
//////// Motor OUTPUT /////////
pinMode(DL1, OUTPUT);
pinMode(DL2, OUTPUT);
pinMode(PWML, OUTPUT);
pinMode(DR1, OUTPUT);
pinMode(DR2, OUTPUT);
pinMode(PWMR, OUTPUT);
////// Servo set ////////////
sv1.attach(ss1);
sv2.attach(ss2);
sv3.attach(ss3);
sv_set();
Wire.begin();
ads.begin();
tone(snd, 800, 100); tone(snd, 1000, 100); tone(snd, 800, 100);
}
void run(int spl, int spr) // ประกาศฟังก์ชัน run(กำลังมอเตอร์ซ้าาย,กำลังมอเตอร์ขวา);
{
if (spl > 0)
{
digitalWrite(DL1, LOW);
digitalWrite(DL2, HIGH);
analogWrite(PWML, spl);
}
else if (spl < 0)
{
digitalWrite(DL1, HIGH);
digitalWrite(DL2, LOW);
analogWrite(PWML, -spl);
}
else
{
digitalWrite(DL1, HIGH);
digitalWrite(DL2, HIGH);
}
//////////////////////////////////////
if (spr > 0)
{
digitalWrite(DR1, LOW);
digitalWrite(DR2, HIGH);
analogWrite(PWMR, spr);
}
else if (spr < 0)
{
digitalWrite(DR1, HIGH);
digitalWrite(DR2, LOW);
analogWrite(PWMR, -spr);
}
else
{
digitalWrite(DR1, HIGH);
digitalWrite(DR2, HIGH);
}
}
void loop() {
int sw = digitalRead(button); // set sw = button
int nob = analogRead(k_nob); // variable nob = k_nob
int menu = map(nob, 0, 4095, 0, 12); // mab nob 0-4095 to 0-12
OLED.clearDisplay(); //clear oled
OLED.setTextColor(WHITE, BLACK); //set color
OLED.setCursor(0, 0); // set cursor position
OLED.setTextSize(2); // set text size 2 point
OLED.print(" "); // space text
OLED.println(menu); // display menu 0 to 12
OLED.setTextSize(1); // set text size 1 point
OLED.println(" LOTUS ARDUIBOT"); // display LOTUS ARDUIBOT
OLED.print(" "); // space text
OLED.print(nob); // display nob
OLED.println(" TEST"); // display TEST
OLED.setTextSize(2); // set text size 2 point
///////////////////////////////////////////////////////////////
if ((menu == 0))
{
}
if ((menu == 1))
{ OLED.println(" SERVO123");
}
if ((menu == 2))
{ OLED.println(" MOTOR");
}
if ((menu == 3))
{
OLED.println(" SOUND");
}
if ((menu == 4))
{
OLED.println(" AnalogI2C");
}
if ((menu == 5))
{
OLED.println(" COMPASS");
}
if ((sw == 0) and (menu == 6))
{
}
if ((sw == 0) and (menu == 7))
{
}
if ((sw == 0) and (menu == 8))
{
}
if ((sw == 0) and (menu == 9))
{
}
if ((sw == 0) and (menu == 10))
{
}
if ((sw == 0) and (menu == 11))
{
}
if ((sw == 0) and (menu == 12))
{
}
//////////////////////////////////////////////////////////////
OLED.display();
if ((sw == 0) and (menu == 0))
{ tone(snd, 800, 100);
}
if ((sw == 0) and (menu == 1))
{
tone(snd, 800, 100); menu1();
}
if ((sw == 0) and (menu == 2))
{
tone(snd, 800, 100); menu2();
}
if ((sw == 0) and (menu == 3))
{
tone(snd, 800, 100); menu3();
}
if ((sw == 0) and (menu == 4))
{
tone(snd, 800, 100); menu4();
}
if ((sw == 0) and (menu == 5))
{
tone(snd, 800, 100); menu5();
}
if ((sw == 0) and (menu == 6))
{
tone(snd, 800, 100); menu6();
}
if ((sw == 0) and (menu == 7))
{
tone(snd, 800, 100); menu7();
}
if ((sw == 0) and (menu == 8))
{
tone(snd, 800, 100); menu8();
}
if ((sw == 0) and (menu == 9))
{
tone(snd, 800, 100); menu9();
}
if ((sw == 0) and (menu == 10))
{
tone(snd, 800, 100); menu10();
}
if ((sw == 0) and (menu == 11))
{
tone(snd, 800, 100); menu11();
}
if ((sw == 0) and (menu == 12))
{
tone(snd, 800, 100); menu12();
}
delay(100);
}
void compass() {
int x, y, z,azimuth;
//qmc.read(&x, &y, &z);
qmc.read(&x, &y, &z,&azimuth);
/* Serial.print("x: ");
Serial.print(x);
Serial.print(" y: ");
Serial.print(y);
Serial.print(" z: ");
Serial.print(z);
Serial.println();
*/
OLED.clearDisplay();
OLED.setTextColor(WHITE,BLACK);
OLED.setCursor(0,0);
OLED.setTextSize(2);
OLED.print(" x = "); OLED.println(x);
OLED.print(" y = "); OLED.println(y);
OLED.print(" z = "); OLED.println(z);
OLED.print("Azi= "); OLED.println(azimuth);
OLED.display();
delay(50);
}
void ads1115(void)
{while(true){
int16_t adc0,adc1,adc2,adc3;
adc0 = ads.readADC_SingleEnded(0);
adc1 = ads.readADC_SingleEnded(1);
adc2 = ads.readADC_SingleEnded(2);
adc3 = ads.readADC_SingleEnded(3);
/*
Serial.print("AIN0: "); Serial.print("AIN1: "); Serial.print("AIN2: "); Serial.println("AIN3: ");
Serial.print(adc0);Serial.print(" ");
Serial.print(adc1);Serial.print(" ");
Serial.print(adc2);Serial.print(" ");
Serial.print(adc3);Serial.println(" ");
*/
OLED.clearDisplay();
OLED.setTextColor(WHITE,BLACK);
OLED.setCursor(0,0);
OLED.setTextSize(2);
OLED.print("AIN0="); OLED.println(adc0);
OLED.print("AIN1="); OLED.println(adc1);
OLED.print("AIN2="); OLED.println(adc2);
OLED.print("AIN3="); OLED.println(adc3);
OLED.display();
delay(10);
}}
void motor()
{ //-------------- forward-------------- //
OLED.clearDisplay();
OLED.setTextColor(WHITE, BLACK);
OLED.setCursor(0, 0);
OLED.setTextSize(2);
OLED.println(" ML MR");
OLED.println(" F F");
OLED.setTextSize(1);
OLED.println(" -------------------");
OLED.setTextSize(2);
OLED.println(" FORWARD");
OLED.display();
run(100, 100); delay(1000); tone(3, 1000, 500);
//-------------- back ward-------------- //
OLED.clearDisplay();
OLED.setTextColor(WHITE, BLACK);
OLED.setCursor(0, 0);
OLED.setTextSize(2);
OLED.println(" ML MR");
OLED.println(" B B");
OLED.setTextSize(1);
OLED.println(" -------------------");
OLED.setTextSize(2);
OLED.println(" BACK");
OLED.display();
run(-100, -100); delay(2000); tone(3, 1000, 500);
//------------------ trun left-----------------------------//
OLED.clearDisplay();
OLED.setTextColor(WHITE, BLACK);
OLED.setCursor(0, 0);
OLED.setTextSize(2);
OLED.println(" ML MR");
OLED.println(" B F");
OLED.setTextSize(1);
OLED.println(" -------------------");
OLED.setTextSize(2);
OLED.println(" LEFT");
OLED.display();
run(-100, 100); delay(2000); tone(3, 1000, 500);
//------------------turn right-----------------------------//
OLED.clearDisplay();
OLED.setTextColor(WHITE, BLACK);
OLED.setCursor(0, 0);
OLED.setTextSize(2);
OLED.println(" ML MR");
OLED.println(" F B");
OLED.setTextSize(1);
OLED.println(" -------------------");
OLED.setTextSize(2);
OLED.println(" RIGHT");
OLED.display();
run(100, -100); delay(2000); tone(3, 1000, 500);
//------------------- stop motor----------------------------//
OLED.clearDisplay();
OLED.setTextColor(WHITE, BLACK);
OLED.setCursor(0, 0);
OLED.setTextSize(2);
OLED.println(" ML MR");
OLED.println(" 0 0");
OLED.setTextSize(1);
OLED.println(" -------------------");
OLED.setTextSize(2);
OLED.println(" STOP");
OLED.display();
run(0, 0); delay(2000); tone(3, 1000, 500);
}
void sv_knob() {
while (true) {
int vr = analogRead(A7);
int nob = map(vr, 0, 4095, 0, 180);
OLED.clearDisplay();
OLED.setTextColor(WHITE, BLACK);
OLED.setCursor(0, 0);
OLED.setTextSize(2);
OLED.print("SV1 = ");
OLED.println(nob);
OLED.print("SV2 = ");
OLED.println(nob);
OLED.print("SV3 = ");
OLED.println(nob);
OLED.display();
sv1.write(nob);
sv2.write(nob);
sv3.write(nob);
delay(50);
}
}
/////////////////////////////////////////////////////
void sv_set()
{ sv1.write(40);
}
void sound() {
tone(snd, 660, 100);
delay(150);
tone(snd, 660, 100);
delay(300);
tone(snd, 660, 100);
delay(300);
tone(snd, 510, 100);
delay(100);
tone(snd, 660, 100);
delay(300);
tone(snd, 770, 100);
delay(550);
tone(snd, 380, 100);
delay(575);
tone(snd, 510, 100);
delay(450);
tone(snd, 380, 100);
delay(400);
tone(snd, 320, 100);
delay(500);
tone(snd, 440, 100);
delay(300);
tone(snd, 480, 80);
delay(330);
tone(snd, 450, 100);
delay(150);
tone(snd, 430, 100);
delay(300);
tone(snd, 380, 100);
delay(200);
tone(snd, 660, 80);
delay(200);
tone(snd, 760, 50);
delay(150);
tone(snd, 860, 100);
delay(300);
tone(snd, 700, 80);
delay(150);
tone(snd, 760, 50);
delay(350);
tone(snd, 660, 80);
delay(300);
tone(snd, 520, 80);
delay(150);
tone(snd, 580, 80);
delay(150);
tone(snd, 480, 80);
delay(500);
tone(snd, 510, 100);
delay(450);
tone(snd, 380, 100);
delay(400);
tone(snd, 320, 100);
delay(500);
tone(snd, 440, 100);
delay(300);
tone(snd, 480, 80);
delay(330);
tone(snd, 450, 100);
delay(150);
tone(snd, 430, 100);
delay(300);
tone(snd, 380, 100);
delay(200);
tone(snd, 660, 80);
delay(200);
tone(snd, 760, 50);
delay(150);
tone(snd, 860, 100);
delay(300);
tone(snd, 700, 80);
delay(150);
tone(snd, 760, 50);
delay(350);
tone(snd, 660, 80);
delay(300);
tone(snd, 520, 80);
delay(150);
tone(snd, 580, 80);
delay(150);
tone(snd, 480, 80);
delay(500);
tone(snd, 500, 100);
delay(300);
tone(snd, 760, 100);
delay(100);
tone(snd, 720, 100);
delay(150);
tone(snd, 680, 100);
delay(150);
tone(snd, 620, 150);
delay(300);
tone(snd, 650, 150);
delay(300);
tone(snd, 380, 100);
delay(150);
tone(snd, 430, 100);
delay(150);
tone(snd, 500, 100);
delay(300);
tone(snd, 430, 100);
delay(150);
tone(snd, 500, 100);
delay(100);
tone(snd, 570, 100);
delay(220);
tone(snd, 500, 100);
delay(300);
tone(snd, 760, 100);
delay(100);
tone(snd, 720, 100);
delay(150);
tone(snd, 680, 100);
delay(150);
tone(snd, 620, 150);
delay(300);
tone(snd, 650, 200);
delay(300);
tone(snd, 1020, 80);
delay(300);
tone(snd, 1020, 80);
delay(150);
tone(snd, 1020, 80);
delay(300);
tone(snd, 380, 100);
delay(300);
tone(snd, 500, 100);
delay(300);
tone(snd, 760, 100);
delay(100);
tone(snd, 720, 100);
delay(150);
tone(snd, 680, 100);
delay(150);
tone(snd, 620, 150);
delay(300);
tone(snd, 650, 150);
delay(300);
tone(snd, 380, 100);
delay(150);
tone(snd, 430, 100);
delay(150);
tone(snd, 500, 100);
delay(300);
tone(snd, 430, 100);
delay(150);
tone(snd, 500, 100);
delay(100);
tone(snd, 570, 100);
delay(420);
tone(snd, 585, 100);
delay(450);
tone(snd, 550, 100);
delay(420);
tone(snd, 500, 100);
delay(360);
tone(snd, 380, 100);
delay(300);
tone(snd, 500, 100);
delay(300);
tone(snd, 500, 100);
delay(150);
tone(snd, 500, 100);
delay(300);
tone(snd, 500, 100);
delay(300);
tone(snd, 760, 100);
delay(100);
tone(snd, 720, 100);
delay(150);
tone(snd, 680, 100);
delay(150);
tone(snd, 620, 150);
delay(300);
tone(snd, 650, 150);
delay(300);
tone(snd, 380, 100);
delay(150);
tone(snd, 430, 100);
delay(150);
tone(snd, 500, 100);
delay(300);
tone(snd, 430, 100);
delay(150);
tone(snd, 500, 100);
delay(100);
tone(snd, 570, 100);
delay(220);
tone(snd, 500, 100);
delay(300);
tone(snd, 760, 100);
delay(100);
tone(snd, 720, 100);
delay(150);
tone(snd, 680, 100);
delay(150);
tone(snd, 620, 150);
delay(300);
tone(snd, 650, 200);
delay(300);
tone(snd, 1020, 80);
delay(300);
tone(snd, 1020, 80);
delay(150);
tone(snd, 1020, 80);
delay(300);
tone(snd, 380, 100);
delay(300);
tone(snd, 500, 100);
delay(300);
tone(snd, 760, 100);
delay(100);
tone(snd, 720, 100);
delay(150);
tone(snd, 680, 100);
delay(150);
tone(snd, 620, 150);
delay(300);
tone(snd, 650, 150);
delay(300);
tone(snd, 380, 100);
delay(150);
tone(snd, 430, 100);
delay(150);
tone(snd, 500, 100);
delay(300);
tone(snd, 430, 100);
delay(150);
tone(snd, 500, 100);
delay(100);
tone(snd, 570, 100);
delay(420);
tone(snd, 585, 100);
delay(450);
tone(snd, 550, 100);
delay(420);
tone(9, 500, 100);
delay(360);
tone(snd, 380, 100);
delay(300);
tone(snd, 500, 100);
delay(300);
tone(snd, 500, 100);
delay(150);
tone(snd, 500, 100);
delay(300);
tone(snd, 500, 60);
delay(150);
tone(snd, 500, 80);
delay(300);
tone(snd, 500, 60);
delay(350);
tone(snd, 500, 80);
delay(150);
tone(snd, 580, 80);
delay(350);
tone(snd, 660, 80);
delay(150);
tone(snd, 500, 80);
delay(300);
tone(snd, 430, 80);
delay(150);
tone(snd, 380, 80);
delay(600);
tone(snd, 500, 60);
delay(150);
tone(snd, 500, 80);
delay(300);
tone(snd, 500, 60);
delay(350);
tone(snd, 500, 80);
delay(150);
tone(snd, 580, 80);
delay(150);
tone(snd, 660, 80);
delay(550);
tone(snd, 870, 80);
delay(325);
tone(snd, 760, 80);
delay(600);
tone(snd, 500, 60);
delay(150);
tone(snd, 500, 80);
delay(300);
tone(snd, 500, 60);
delay(350);
tone(snd, 500, 80);
delay(150);
tone(snd, 580, 80);
delay(350);
tone(snd, 660, 80);
delay(150);
tone(snd, 500, 80);
delay(300);
tone(snd, 430, 80);
delay(150);
tone(snd, 380, 80);
delay(600);
tone(snd, 660, 100);
delay(150);
tone(snd, 660, 100);
delay(300);
tone(snd, 660, 100);
delay(300);
tone(snd, 510, 100);
delay(100);
tone(snd, 660, 100);
delay(300);
tone(snd, 770, 100);
delay(550);
tone(snd, 380, 100);
delay(575);
}
//////////////write and use code menu ////////////
void menu1() /// write and use code menu 1
{
sv_knob(); // servo test
}
void menu2() /// write and use code menu
{ motor(); // dc motor test
}
void menu3() /// write and use code menu 3
{ sound(); // sound test
}
void menu4() /// write and use code menu 4
{ads1115();
}
void menu5() /// write and use code menu 5
{compass();
}
void menu6() /// write and use code menu 6
{
}
void menu7() /// write and use code menu 7
{
}
void menu8() /// write and use code menu 8
{
}
void menu9() /// write and use code menu 9
{
}
void menu10() /// write and use code menu 10
{
}
void menu11() /// write and use code menu 11
{
}
void menu12() /// write and use code menu 12
{
}