EasyManua.ls Logo

Keyestudio ESP32 - Page 72

Keyestudio ESP32
344 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
ESP32 Starter Kit
Comparison Diagram of Flat, Natural and Sharp
Code
/*
keyestudio ESP32 Inventor Learning Kit
Project 8.2 Music Performer
http://www.keyestudio.com
*/
int beeppin = 5; //Define the speaker pin to IO5
// doremifasolasi
int doremi[] = {262, 294, 330, 370, 392, 440, 494, //Falt 0-6
523, 587, 659, 698, 784, 880, 988, //Natural 7-13
1047,1175,1319,1397,1568,1760,1967}; //Sharp 14-20
int happybirthday[] = {5,5,6,5,8,7,5,5,6,5,9,8,5,5,12,10,8,7,6,11,11,10,8,9,8}; //Find
˓the number in arrey doremi[] according to the numbered musical notation
int meter[] = {1,1,2,2,2,4, 1,1,2,2,2,4, 1,1,2,2,2,2,2, 1,1,2,2,2,4}; // Beats
void setup() {
pinMode(beeppin, OUTPUT); //Set IO5 pin to output mode
}
void loop() {
for( int i = 0 ; i <= 24 ;i++){ //i<=24, because there are only 24 tones in this
˓song
//Use tone()function to generate a waveform in "frequency"
tone(beeppin, doremi[happybirthday[i] - 1]);
delay(meter[i] * 200); //Wait for 1000ms
noTone(beeppin);//Stop singing
}
}
68 Chapter 8. Arduino Tutorial

Table of Contents