Arduino Piano With Manual and 7 Presets Songs
by ECEPanda in Circuits > Arduino
3198 Views, 6 Favorites, 0 Comments
Arduino Piano With Manual and 7 Presets Songs
Arduino Piano Keyboard interfacing with LCD has 2 mode.
The Manual Mode & The presets mode. I used 7 Pushbutton for a simple 7 keys piano and 1 button for Setup Mode to switch to 7 presets songs.
. Preset mode songs: Click the setup mode button first.
- super mario stage 1
- super mario stage 2
- fur elise
- despacito
- joy to the world
- jingle bells
- star wars
Materials
Materials:
- Arduino UNO ( I used clone of it)
- Breadboard(long)
- 1 LED (any color you want. I used blue)
- 8 - 10k ohms resistor
- 2 - 220 ohms resistor
- 1 Piezo buzzer
- 8- tactile push-button
- Connecting Wires(male to male) -- atleast 40pcs
- 1 LCD 16x2 w/ header pins(i used lcd w/ backlight)
- Potentiometer
Pushbutton Connections
Pushbutton has 4 pins. By default(Button is not pressed) A & B are connected , C & D are also connected. So if the button is pressed ABCD are all connected.
1.) Connect Pin D of the Pushbutton w/ a 10 kilo ohms resistor(Doesn't matter which leg cause resistor has no polarity). The other leg of the resistor is connected to Ground(GND) of the Arduino.
2.) Connect Pin B of the Pushbutton to 5 volts(5V) of the Arduino.
3.) Connect Pin C of the Pushbutton to pins of the Arduino (2,3,4,5,6,7,A0, A1).
LED Connections
Light emitting Diode (LED) has a polarity, the Anode leg which is the positive & the Cathode leg which is the negative. The brightness of LED depends on what resistor you use. I used 220 ohms.
1.) Connect the Anode leg or the longer leg of the LED to a 220 ohms resistor.
2.) Connect the other leg of the resistor to the Pins of the Arduino(A5).
3.) Connect the Cathode leg of the LED to Ground(GND).
Piezobuzzer Connections
The buzzer has two leg. Look for the + mark and that is the positive leg.
- Connect the positive leg to Arduino pin A2.
- Connect the other leg to Ground.
Liquid Crystal Display & Potentiometer Connections
LCD to Arduino Connections
- VSS --> GND
- VDD --> 5v
- VO(Dispaly Contrast pin) --> Middle leg of potentiometer
- RS(Register Select) --> Arduino D8
- R/W(Read/ Write) --> GND
- E(Enable) --> Arduino D9
- D0 --> not connected
- D1 --> not connected
- D2 --> not connected
- D3 --> not connected
- D4 --> Arduino D10
- D5 --> Arduino D11
- D6 --> Arduino D12
- D7 --> Arduino D13
- A -->200 ohms resistor to 5v
- K --> GND
Schematic Diagram
Program Code :)
<p>link: https://create.arduino.cc/editor/EngrPanda/a77e4711-b034-430a-92dd-894218e9e007/preview</p><p>#define NOTE_C 262<br>#define NOTE_D 294 #define NOTE_E 330 #define NOTE_F 349 #define NOTE_G 392 #define NOTE_A 440 #define NOTE_B 493</p><p>#include <LiquidCrystal.h></p><p> const int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 12, d7 = 13; LiquidCrystal lcd(rs, en, d4, d5, d6, d7);</p><p>//////despacito////</p><p>int noteDuration; int pauseBetweenNotes = 0; int negra; //////////////////STAR WARS////////// const int c = 261; const int d = 294; const int e = 329; const int f = 349; const int g = 391; const int gS = 415; const int a = 440; const int aS = 455; const int b = 466; const int cH = 523; const int cSH = 554; const int dH = 587; const int dSH = 622; const int eH = 659; const int fH = 698; const int fSH = 740; const int gH = 784; const int gSH = 830; const int aH = 880; int counter = 0; //////////////////////////////////// #define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTE_A1 55 #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #define NOTE_AS5 932 #define NOTE_B5 988 #define NOTE_C6 1047 #define NOTE_CS6 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOTE_B6 1976 #define NOTE_C7 2093 #define NOTE_CS7 2217 #define NOTE_D7 2349 #define NOTE_DS7 2489 #define NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 3951 #define NOTE_C8 4186 #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978</p><p>///////////////////////MARIO/////////////////////// #define melodyPin PIEZO //Mario main theme melody int melody[] = { NOTE_E7, NOTE_E7, 0, NOTE_E7, 0, NOTE_C7, NOTE_E7, 0, NOTE_G7, 0, 0, 0, NOTE_G6, 0, 0, 0, NOTE_C7, 0, 0, NOTE_G6, 0, 0, NOTE_E6, 0, 0, NOTE_A6, 0, NOTE_B6, 0, NOTE_AS6, NOTE_A6, 0, NOTE_G6, NOTE_E7, NOTE_G7, NOTE_A7, 0, NOTE_F7, NOTE_G7, 0, NOTE_E7, 0, NOTE_C7, NOTE_D7, NOTE_B6, 0, 0, NOTE_C7, 0, 0, NOTE_G6, 0, 0, NOTE_E6, 0, 0, NOTE_A6, 0, NOTE_B6, 0, NOTE_AS6, NOTE_A6, 0, NOTE_G6, NOTE_E7, NOTE_G7, NOTE_A7, 0, NOTE_F7, NOTE_G7, 0, NOTE_E7, 0, NOTE_C7, NOTE_D7, NOTE_B6, 0, 0 }; //Mario main them tempo int tempo[] = { 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 9, 9, 9, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 9, 9, 9, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, }; //Underworld melody int underworld_melody[] = { NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4, NOTE_AS3, NOTE_AS4, 0, 0, NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4, NOTE_AS3, NOTE_AS4, 0, 0, NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4, NOTE_DS3, NOTE_DS4, 0, 0, NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4, NOTE_DS3, NOTE_DS4, 0, 0, NOTE_DS4, NOTE_CS4, NOTE_D4, NOTE_CS4, NOTE_DS4, NOTE_DS4, NOTE_GS3, NOTE_G3, NOTE_CS4, NOTE_C4, NOTE_FS4, NOTE_F4, NOTE_E3, NOTE_AS4, NOTE_A4, NOTE_GS4, NOTE_DS4, NOTE_B3, NOTE_AS3, NOTE_A3, NOTE_GS3, 0, 0, 0 }; //Underwolrd tempo int underworld_tempo[] = { 12, 12, 12, 12, 12, 12, 6, 3, 12, 12, 12, 12, 12, 12, 6, 3, 12, 12, 12, 12, 12, 12, 6, 3, 12, 12, 12, 12, 12, 12, 6, 6, 18, 18, 18, 6, 6, 6, 6, 6, 6, 18, 18, 18, 18, 18, 18, 10, 10, 10, 10, 10, 10, 3, 3, 3 }; /////////////////////////////////FUR ELISE///////////////// // Fur Elise --> Melody int melody1[] = { NOTE_E5, NOTE_DS5, NOTE_E5, NOTE_DS5, NOTE_E5, NOTE_B4, NOTE_D5, NOTE_C5, NOTE_A4, NOTE_C4, NOTE_E4, NOTE_A4, NOTE_B4, NOTE_E4, NOTE_GS4, NOTE_B4, NOTE_C5, NOTE_E4, NOTE_E5, NOTE_DS5, NOTE_E5, NOTE_DS5, NOTE_E5, NOTE_B4, NOTE_D5, NOTE_C5, NOTE_A4, NOTE_C4, NOTE_E4, NOTE_A4, NOTE_B4, NOTE_E4, NOTE_C5, NOTE_B4, NOTE_A4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_G4, NOTE_F5, NOTE_E5, NOTE_D5, NOTE_F4, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_E4, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_E4, NOTE_E5, NOTE_E4, NOTE_E5, NOTE_E4, NOTE_E5, NOTE_E4, NOTE_E5, NOTE_DS4, NOTE_E5, NOTE_D4, NOTE_E5, NOTE_DS4, NOTE_E5, NOTE_B4, NOTE_D5, NOTE_C5, NOTE_A4, NOTE_C4, NOTE_E4, NOTE_A4, NOTE_B4, NOTE_E4, NOTE_GS4, NOTE_B4, NOTE_C5, NOTE_E4, NOTE_E5, NOTE_DS5,</p><p> NOTE_E5, NOTE_DS5, NOTE_E5, NOTE_B4, NOTE_D5, NOTE_C5, NOTE_A4, NOTE_C4, NOTE_E4, NOTE_A4, NOTE_B4, NOTE_E4, NOTE_C5, NOTE_B4, NOTE_A4, 0, };</p><p>// Main tempo of 'Fur Elise' int tempo1[] = { 9, 9, 9, 9, 9, 9, 9, 9, 3, 9, 9, 9, 3, 9, 9, 9,</p><p> 3, 9, 9, 9, 9, 9, 9, 9, 9, 9, 3, 9, 9, 9, 3, 9,</p><p> 9, 9, 3, 9, 9, 9, 3, 9, 9, 9, 3, 9, 9, 9, 3, 9,</p><p> 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,</p><p> 9, 9, 9, 9, 3, 9, 9, 9, 3, 9, 9, 9, 3, 9, 9, 9,</p><p> 9, 9, 9, 9, 9, 9, 3, 9, 9, 9, 3, 8, 8, 8, 1, 9, }; ////////////////////////////////////// const int BUTTON_C = 2; const int BUTTON_D = 3; const int BUTTON_E = 4; const int BUTTON_F = 5; const int BUTTON_G = 6; const int BUTTON_A = 7; const int BUTTON_B = A0; const int PB = A1; const int LEDBLUE = A5; int buttonStateC = 0; // variable for reading the pushbutton status int buttonStateD = 0; // variable for reading the pushbutton status int buttonStateE = 0; // variable for reading the pushbutton status int buttonStateF = 0; // variable for reading the pushbutton status int buttonStateG = 0; // variable for reading the pushbutton status int buttonStateA = 0; // variable for reading the pushbutton status int buttonStateB = 0; // variable for reading the pushbutton status</p><p>int var1=0; int var2=0; int var3=0; int var4=0; int var5=0; int var6=0; int var7=0; int VAR1=0; const int PIEZO = A2; void setup() { pinMode(BUTTON_C, INPUT); pinMode(BUTTON_D, INPUT); pinMode(BUTTON_E, INPUT); pinMode(BUTTON_F, INPUT); pinMode(BUTTON_G, INPUT); pinMode(BUTTON_A, INPUT); pinMode(BUTTON_B, INPUT); pinMode(PB, INPUT); pinMode(LEDBLUE, OUTPUT); lcd.begin(16, 2); pinMode(PIEZO, OUTPUT);//buzzer negra=640; }</p><p>void loop() { int push= digitalRead(PB);</p><p>if (push==HIGH) { lcd.setCursor(0, 0); lcd.print("1SM 2SM 3ELI 4DES"); lcd.setCursor(0, 1); lcd.print("5JOY 6JING 7S TAR"); VAR1=VAR1+1; delay(300); }</p><p> if (VAR1 == 1) { presets(); digitalWrite(LEDBLUE, HIGH); } else { manualpiano(); digitalWrite(LEDBLUE, LOW); VAR1=0; } }</p><p>void manualpiano() { buttonStateC = digitalRead(BUTTON_C); buttonStateD = digitalRead(BUTTON_D); buttonStateE = digitalRead(BUTTON_E); buttonStateF = digitalRead(BUTTON_F); buttonStateG = digitalRead(BUTTON_G); buttonStateA = digitalRead(BUTTON_A); buttonStateB = digitalRead(BUTTON_B);</p><p> lcd.setCursor(0, 0); lcd.print("Piano ManualMode"); if (buttonStateC == HIGH) { tone(PIEZO, NOTE_C); lcd.setCursor(0, 1); lcd.print("DO"); lcd.setCursor(15, 1); lcd.print("C"); lcd.setCursor(7, 1); lcd.print("1"); } else if (buttonStateD == HIGH) { tone(PIEZO, NOTE_D); lcd.setCursor(7, 1); lcd.print("2"); lcd.setCursor(0, 1); lcd.print("RE"); lcd.setCursor(15, 1); lcd.print("D"); }</p><p> else if (buttonStateE == HIGH) { tone(PIEZO, NOTE_E); lcd.setCursor(7, 1); lcd.print("3"); lcd.setCursor(0, 1); lcd.print("MI"); lcd.setCursor(15, 1); lcd.print("E"); }</p><p> else if (buttonStateF == HIGH) { tone(PIEZO, NOTE_F); lcd.setCursor(7, 1); lcd.print("4"); lcd.setCursor(0, 1); lcd.print("FA"); lcd.setCursor(15, 1); lcd.print("F"); }</p><p> else if (buttonStateG == HIGH) { tone(PIEZO, NOTE_G); lcd.setCursor(7, 1); lcd.print("5"); lcd.setCursor(0, 1); lcd.print("SO"); lcd.setCursor(15, 1); lcd.print("G"); }</p><p> else if (buttonStateA == HIGH) { tone(PIEZO, NOTE_A); lcd.setCursor(7, 1); lcd.print("6"); lcd.setCursor(0, 1); lcd.print("LA"); lcd.setCursor(15, 1); lcd.print("A"); }</p><p> else if (buttonStateB == HIGH) { tone(PIEZO, NOTE_B); lcd.setCursor(7, 1); lcd.print("7"); lcd.setCursor(0, 1); lcd.print("TI"); lcd.setCursor(15, 1); lcd.print("B"); } else { noTone(PIEZO); } }</p><p>void presets() { buttonStateC = digitalRead(BUTTON_C); buttonStateD = digitalRead(BUTTON_D); buttonStateE = digitalRead(BUTTON_E); buttonStateF = digitalRead(BUTTON_F); buttonStateG = digitalRead(BUTTON_G); buttonStateA = digitalRead(BUTTON_A); buttonStateB = digitalRead(BUTTON_B);</p><p> if(buttonStateC == HIGH) { var1=1; var2=0; var3=0; var4=0; var5=0; var6=0; var7=0; } if(buttonStateD == HIGH) { var1=0; var2=1; var3=0; var4=0; var5=0; var6=0; var7=0; } if(buttonStateE == HIGH) { var1=0; var2=0; var3=1; var4=0; var5=0; var6=0; var7=0; } if(buttonStateF == HIGH) { var1=0; var2=0; var3=0; var4=1; var5=0; var6=0; var7=0; } if(buttonStateG == HIGH) { var1=0; var2=0; var3=0; var4=0; var5=1; var6=0; var7=0; } if(buttonStateA == HIGH) { var1=0; var2=0; var3=0; var4=0; var5=0; var6=1; var7=0; } if(buttonStateB == HIGH) { var1=0; var2=0; var3=0; var4=0; var5=0; var6=0; var7=1; } </p><p> if (var1 == 1) { for(var1 = 0; var1 >= var1; var1++){ lcd.setCursor(0, 0); lcd.print("Now Playing!!!!!"); lcd.setCursor(0, 1); lcd.print("Super Mario!!!!"); sing(1); var1 = 0; if(var1 == 0){ noTone(PIEZO); delay(100); break; } } } else if (var2 == 1) { for(var2 = 0; var2 >= var2; var2++){ lcd.setCursor(0, 0); lcd.print("Now Playing!!!!!"); lcd.setCursor(0, 1); lcd.print("SuperMario2!!!!"); sing(2); var2 = 0; if(var2 == 0){ noTone(PIEZO); delay(100); break; } } } else if (var3 == 1) { for(var3 = 0; var3 >= var3; var3++){ lcd.setCursor(0, 0); lcd.print("Now Playing!!!!!"); lcd.setCursor(0, 1); lcd.print("Elise!!!!!!!"); elise(1); var3 = 0; if(var3 == 0){ noTone(PIEZO); delay(100); break; } } } else if (var4 == 1) { for(var4 = 0; var4 >= var4; var4++){ lcd.setCursor(0, 0); lcd.print("Now Playing!!!!!"); lcd.setCursor(0, 1); lcd.print("Despacito!!!!!"); despacito(); var4 = 0; if(var4 == 0){ noTone(PIEZO); delay(100); break; } } }</p><p> else if (var5 == 1) { for(var5 = 0; var5 >= var5; var5++){ lcd.setCursor(0, 0); lcd.print("Now Playing!!!!!"); lcd.setCursor(0, 1); lcd.print("Joy_to_the_World!"); Joy_to_the_World(); var5 = 0; if(var5 == 0){ noTone(PIEZO); delay(100); break; } } } else if (var6 == 1) { for(var6 = 0; var6 >= var6; var6++){ lcd.setCursor(0, 0); lcd.print("Now Playing!!!!!"); lcd.setCursor(0, 1); lcd.print("Jingle_Bells!!!"); Jingle_Bells(); var6 = 0; if(var6 == 0){ noTone(PIEZO); delay(100); break; } } } else if (var7 == 1) { for(var7 = 0; var7 >= var7; var7++){ lcd.setCursor(0, 0); lcd.print("Now Playing!!!!"); lcd.setCursor(0, 1); lcd.print("starwars!!!!!"); starwars(); var7 = 0; if(var7 == 0){ noTone(PIEZO); delay(100); break; } } } else { noTone(PIEZO); } }</p><p> ///////////////////////MARIO/////////////////////// int song = 0; void sing(int s) { // iterate over the notes of the melody: song = s; if (song == 2) { Serial.println(" 'Underworld Theme'"); int size = sizeof(underworld_melody) / sizeof(int); for (int thisNote = 0; thisNote < size; thisNote++) { // to calculate the note duration, take one second // divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000 / underworld_tempo[thisNote]; buzz(melodyPin, underworld_melody[thisNote], noteDuration); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: buzz(melodyPin, 0, noteDuration); } } else { Serial.println(" 'Mario Theme'"); int size = sizeof(melody) / sizeof(int); for (int thisNote = 0; thisNote < size; thisNote++) { // to calculate the note duration, take one second // divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000 / tempo[thisNote]; buzz(melodyPin, melody[thisNote], noteDuration); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: buzz(melodyPin, 0, noteDuration); } } } /////////////////////FUR ELISE/////////////// int fur = 0; void elise(int s) { fur = s; if (fur == 1){ Serial.println("'Fur Elise'"); int size = sizeof(melody) / sizeof(int); for (int thisNote = 0; thisNote < size; thisNote++) { int noteDuration = 1000 / tempo1[thisNote]; buzz(melodyPin, melody1[thisNote], noteDuration); int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); buzz(melodyPin, 0, noteDuration); } } } ////////////////////FUR ELISE///////////// void buzz(int targetPin, long frequency, long length) { long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions //// 1 second's worth of microseconds, divided by the frequency, then split in half since //// there are two phases to each cycle long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing //// multiply frequency, which is really cycles per second, by the number of seconds to //// get the total number of cycles to produce for (long i = 0; i < numCycles; i++) { // for the calculated length of time... digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram delayMicroseconds(delayValue); // wait for the calculated delay value digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram delayMicroseconds(delayValue); // wait again or the calculated delay value } }</p><p>//////////////DESPACITO/////// void despacito(){ notars(negra, NOTE_D5); notars(negra, NOTE_CS5); // (1) notars(negra/2, NOTE_B4); notars(negra/4, NOTE_FS4); // (2) delay(negra/4); // (3) notars(negra/4, NOTE_FS4); notars(negra/4, NOTE_FS4); // (4) notars(negra/4, NOTE_FS4); notars(negra/4, NOTE_FS4); // (1) notars(negra/4, NOTE_FS4);</p><p> notars(negra/4, NOTE_B4); notars(negra/4, NOTE_B4); // (2) notars(negra/4, NOTE_B4); // (3) notars(negra/2, NOTE_B4); // (4) </p><p> notars(negra/4, NOTE_A4); notars(negra/4, NOTE_B4); // (1) delay(negra/4); delay(negra/4); notars(negra/4, NOTE_G4); // (2) delay(negra/4); // (3) //...... notars(negra/4, NOTE_G4); notars(negra/4, NOTE_G4); // (4) notars(negra/4, NOTE_G4); notars(negra/4, NOTE_G4); // (1) notars(negra/4, NOTE_G4); </p><p> notars(negra/4, NOTE_B4); notars(negra/4, NOTE_B4); // (2) notars(negra/4, NOTE_B4); // (3) notars(negra/2, NOTE_B4); // (4) notars(negra/4, NOTE_CS5); notars(negra/4, NOTE_D5); // (1) delay(negra/4); delay(negra/4); notars(negra/4, NOTE_A4); // (2) delay(negra/4); // (3) notars(negra/4, NOTE_A4); notars(negra/4, NOTE_A4); // (4) notars(negra/4, NOTE_A4); notars(negra/4, NOTE_A4); // (1) notars(negra/4, NOTE_D5); notars(negra/4, NOTE_CS5); notars(negra/4, NOTE_D5); // (2) notars(negra/4, NOTE_CS5); // (3) notars(negra/2, NOTE_D5); // (4) // notars(negra/4, NOTE_E5); notars_jai(negra/2, NOTE_E5,negra/4); // (1) // notars(negra/2, NOTE_E5); </p><p> //----------------------------------------------- tone(PIEZO,NOTE_CS5 ,negra*3/4); //----------------------------------------------- delay(negra/4); delay(negra/4); // (2) delay(negra/4); // (3) noTone(PIEZO); delay(negra/4); //-------------- delay(negra/4); // (4) </p><p> delay(negra/4); delay(negra/4); } void notars(int noteDuration,int LaNota ){</p><p> //noteDuration=negra/4; tone(PIEZO,LaNota ,noteDuration*0.9); // pauseBetweenNotes = noteDuration * 1.30; pauseBetweenNotes = noteDuration * 1.1; delay(pauseBetweenNotes); noTone(PIEZO); </p><p>} void notars_jai(int noteDuration,int LaNota ,int Desfase){</p><p> //noteDuration=negra/4; tone(PIEZO,LaNota ,noteDuration*0.9); // pauseBetweenNotes = noteDuration * 1.30; pauseBetweenNotes = noteDuration * 1.1; delay(Desfase); delay(pauseBetweenNotes-Desfase); noTone(PIEZO); </p><p>} ////////////////////////////////STAR WARS/////////// void beep(int note, int duration) { //Play tone on PIEZO tone(PIEZO, note, duration); //Play different LED depending on value of 'counter' if(counter % 2 == 0) { digitalWrite(LED1, HIGH); digitalWrite(LED2, HIGH); digitalWrite(LED3, HIGH); digitalWrite(LED4, HIGH); delay(duration); digitalWrite(LED1, LOW); digitalWrite(LED2, LOW); digitalWrite(LED3, LOW); digitalWrite(LED4, LOW); }else { digitalWrite(LED5, HIGH); digitalWrite(LED6, HIGH); digitalWrite(LED7, HIGH); delay(duration); digitalWrite(LED5, LOW); digitalWrite(LED6, LOW); digitalWrite(LED7, LOW); } //Stop tone on PIEZO noTone(PIEZO); delay(50); //Increment counter counter++; } void firstSection() { beep(a, 500); beep(a, 500); beep(a, 500); beep(f, 350); beep(cH, 150); beep(a, 500); beep(f, 350); beep(cH, 150); beep(a, 650); delay(500); beep(eH, 500); beep(eH, 500); beep(eH, 500); beep(fH, 350); beep(cH, 150); beep(gS, 500); beep(f, 350); beep(cH, 150); beep(a, 650); delay(500); } void secondSection() { beep(aH, 500); beep(a, 300); beep(a, 150); beep(aH, 500); beep(gSH, 325); beep(gH, 175); beep(fSH, 125); beep(fH, 125); beep(fSH, 250); delay(325); beep(aS, 250); beep(dSH, 500); beep(dH, 325); beep(cSH, 175); beep(cH, 125); beep(b, 125); beep(cH, 250); delay(350); } ////////////////////////////////////////JINGLE BELL///// void Jingle_Bells() {</p><p> tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 293, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 391, 187.5); delay(208.333333333); tone(PIEZO, 293, 562.5); delay(625.0); tone(PIEZO, 293, 93.75); delay(104.166666667); tone(PIEZO, 293, 93.75); delay(104.166666667); tone(PIEZO, 293, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 391, 187.5); delay(208.333333333); tone(PIEZO, 329, 750.0); delay(833.333333333); tone(PIEZO, 329, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 369, 750.0); delay(833.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 493, 750.0); delay(833.333333333); tone(PIEZO, 293, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 391, 187.5); delay(208.333333333); tone(PIEZO, 293, 750.0); delay(833.333333333); tone(PIEZO, 293, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 391, 187.5); delay(208.333333333); tone(PIEZO, 329, 656.25); delay(729.166666667); tone(PIEZO, 329, 93.75); delay(104.166666667); tone(PIEZO, 329, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 659, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 391, 375.0); delay(416.666666667); tone(PIEZO, 587, 375.0); delay(416.666666667); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 375.0); delay(416.666666667); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 375.0); delay(416.666666667); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 391, 281.25); delay(312.5); tone(PIEZO, 440, 93.75); delay(104.166666667); tone(PIEZO, 493, 750.0); delay(833.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 281.25); delay(312.5); tone(PIEZO, 523, 93.75); delay(104.166666667); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 93.75); delay(104.166666667); tone(PIEZO, 493, 93.75); delay(104.166666667); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 440, 375.0); delay(416.666666667); tone(PIEZO, 587, 375.0); delay(416.666666667); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 375.0); delay(416.666666667); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 375.0); delay(416.666666667); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 391, 281.25); delay(312.5); tone(PIEZO, 440, 93.75); delay(104.166666667); tone(PIEZO, 493, 750.0); delay(833.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 281.25); delay(312.5); tone(PIEZO, 523, 93.75); delay(104.166666667); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 93.75); delay(104.166666667); tone(PIEZO, 493, 93.75); delay(104.166666667); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 391, 375.0); delay(416.666666667); tone(PIEZO, 783, 187.5); delay(208.333333333); delay(208.333333333); tone(PIEZO, 293, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 391, 187.5); delay(208.333333333); tone(PIEZO, 293, 562.5); delay(625.0); tone(PIEZO, 293, 93.75); delay(104.166666667); tone(PIEZO, 293, 93.75); delay(104.166666667); tone(PIEZO, 293, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 391, 187.5); delay(208.333333333); tone(PIEZO, 329, 750.0); delay(833.333333333); tone(PIEZO, 329, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 369, 750.0); delay(833.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 493, 750.0); delay(833.333333333); tone(PIEZO, 293, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 391, 187.5); delay(208.333333333); tone(PIEZO, 293, 750.0); delay(833.333333333); tone(PIEZO, 293, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 391, 187.5); delay(208.333333333); tone(PIEZO, 329, 656.25); delay(729.166666667); tone(PIEZO, 329, 93.75); delay(104.166666667); tone(PIEZO, 329, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 659, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 391, 375.0); delay(416.666666667); tone(PIEZO, 587, 375.0); delay(416.666666667); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 375.0); delay(416.666666667); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 375.0); delay(416.666666667); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 391, 281.25); delay(312.5); tone(PIEZO, 440, 93.75); delay(104.166666667); tone(PIEZO, 493, 750.0); delay(833.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 281.25); delay(312.5); tone(PIEZO, 523, 93.75); delay(104.166666667); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 93.75); delay(104.166666667); tone(PIEZO, 493, 93.75); delay(104.166666667); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 440, 375.0); delay(416.666666667); tone(PIEZO, 587, 375.0); delay(416.666666667); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 375.0); delay(416.666666667); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 375.0); delay(416.666666667); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 391, 281.25); delay(312.5); tone(PIEZO, 440, 93.75); delay(104.166666667); tone(PIEZO, 493, 750.0); delay(833.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 523, 281.25); delay(312.5); tone(PIEZO, 523, 93.75); delay(104.166666667); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 187.5); delay(208.333333333); tone(PIEZO, 493, 93.75); delay(104.166666667); tone(PIEZO, 493, 93.75); delay(104.166666667); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 587, 187.5); delay(208.333333333); tone(PIEZO, 523, 187.5); delay(208.333333333); tone(PIEZO, 440, 187.5); delay(208.333333333); tone(PIEZO, 391, 375.0); delay(416.666666667); tone(PIEZO, 783, 187.5); delay(208.333333333); } //////////////////////JOY TO THE WORLD////////////// void Joy_to_the_World() {</p><p> // tone(PIEZO, 587, 450.0); delay(500.0); tone(PIEZO, 554, 337.5); delay(375.0); // tone(PIEZO, 493, 112.5); delay(125.0);</p><p> tone(PIEZO, 440, 675.0); delay(750.0); // // tone(PIEZO, 391, 225.0); delay(250.0); tone(PIEZO, 369, 450.0); delay(500.0); // // tone(PIEZO, 329, 450.0); delay(500.0); tone(PIEZO, 293, 675.0); delay(750.0); // tone(PIEZO, 440, 225.0); delay(250.0); // tone(PIEZO, 493, 670.3125); delay(744.791666667); delay(5.20833333333); // // tone(PIEZO, 493, 225.0); delay(250.0); tone(PIEZO, 554, 670.3125); delay(744.791666667); delay(5.20833333333); // // tone(PIEZO, 554, 225.0); delay(250.0); tone(PIEZO, 587, 670.3125); delay(744.791666667); delay(5.20833333333); // // tone(PIEZO, 587, 220.3125); delay(244.791666667); delay(5.20833333333); tone(PIEZO, 587, 225.0); delay(250.0); // // tone(PIEZO, 554, 225.0); delay(250.0); tone(PIEZO, 493, 225.0); delay(250.0); // // tone(PIEZO, 440, 220.3125); delay(244.791666667); delay(5.20833333333); tone(PIEZO, 440, 337.5); delay(375.0); // // tone(PIEZO, 391, 112.5); delay(125.0); tone(PIEZO, 369, 225.0); delay(250.0); tone(PIEZO, 587, 220.3125); delay(244.791666667); delay(5.20833333333); // // tone(PIEZO, 587, 225.0); delay(250.0); tone(PIEZO, 554, 225.0); delay(250.0); // // tone(PIEZO, 493, 225.0); delay(250.0); tone(PIEZO, 440, 220.3125); delay(244.791666667); delay(5.20833333333); // // tone(PIEZO, 440, 337.5); // delay(375.0); // tone(PIEZO, 391, 112.5); delay(125.0); tone(PIEZO, 369, 220.3125); delay(244.791666667); delay(5.20833333333); // // tone(PIEZO, 369, 220.3125); delay(244.791666667); delay(5.20833333333); tone(PIEZO, 369, 220.3125); delay(244.791666667); delay(5.20833333333); // // tone(PIEZO, 369, 220.3125); delay(244.791666667); delay(5.20833333333); tone(PIEZO, 369, 220.3125); delay(244.791666667); delay(5.20833333333); // // tone(PIEZO, 369, 112.5); delay(125.0); tone(PIEZO, 391, 112.5); delay(125.0); // // tone(PIEZO, 440, 675.0); // delay(750.0); // tone(PIEZO, 391, 112.5); delay(125.0); tone(PIEZO, 369, 112.5); delay(125.0); tone(PIEZO, 329, 220.3125); delay(244.791666667); delay(5.20833333333); // // tone(PIEZO, 329, 220.3125); delay(244.791666667); delay(5.20833333333); tone(PIEZO, 329, 220.3125); delay(244.791666667); delay(5.20833333333); tone(PIEZO, 329, 112.5); delay(125.0); tone(PIEZO, 369, 112.5); delay(125.0); // // tone(PIEZO, 391, 675.0); // delay(750.0); // tone(PIEZO, 369, 112.5); delay(125.0); tone(PIEZO, 329, 112.5); delay(125.0); tone(PIEZO, 293, 225.0); delay(250.0); // // tone(PIEZO, 587, 450.0); delay(500.0); tone(PIEZO, 493, 225.0); delay(250.0); // // tone(PIEZO, 440, 337.5); delay(375.0); tone(PIEZO, 391, 112.5); delay(125.0); // // tone(PIEZO, 369, 225.0); delay(250.0); tone(PIEZO, 391, 225.0); delay(250.0); // // tone(PIEZO, 369, 450.0); delay(500.0); // // tone(PIEZO, 329, 450.0); // delay(500.0); noTone(PIEZO); } /////////////starwars////// void starwars() { firstSection(); //Play second section secondSection(); //Variant 1 beep(f, 250); beep(gS, 500); beep(f, 350); beep(a, 125); beep(cH, 500); beep(a, 375); beep(cH, 125); beep(eH, 650); delay(500); //Repeat second section secondSection(); //Variant 2 beep(f, 250); beep(gS, 500); beep(f, 375); beep(cH, 125); beep(a, 500); beep(f, 375); beep(cH, 125); beep(a, 650); delay(650); }</p>