hi,
so I am trying to make my piezo play "What makes You Beautiful" by One Direction and I have translated the notes from the sheet music so they readable by the pitches.h library but for some reason when I run the program the piezo only plays the first few notes in the melody.
This is the code I've made for the song, I have it in a different tab because I am coding six songs and it is easier to have them in separate tabs. Also some are commented out because I was getting the memory error.
[void Song4() {
lcd.setCursor(1, 0);
lcd.print("Now playing...");
lcd.setCursor(0, 1);
lcd.print(" WMYB");
// notes in the melody:
int melody[] = {
NOTE_E4, 0, NOTE_E4, NOTE_E4, 0, NOTE_E4,
NOTE_DS4, 0, NOTE_DS4, 0, NOTE_DS4, 0, NOTE_DS4,
NOTE_E4, 0, NOTE_E4, NOTE_E4, 0, NOTE_E4,
NOTE_DS4, NOTE_DS4, NOTE_DS4, NOTE_E4, NOTE_E4, NOTE_E4,
NOTE_E4, 0, 0, NOTE_E4, NOTE_E4, NOTE_E4,
NOTE_E4, 0, 0, NOTE_E4, NOTE_E4, NOTE_E4,
NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_FS4,
NOTE_GS4, NOTE_FS4, 0, NOTE_E4, NOTE_E4, NOTE_E4
//NOTE_E4, 0, 0, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, 0, 0, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4,
//NOTE_FS4, NOTE_GS4, NOTE_GS4, 0, 0, NOTE_E4, NOTE_GS4, NOTE_B4, NOTE_CS5, NOTE_CS5, NOTE_B4, NOTE_GS4, NOTE_GS4, NOTE_GS4, NOTE_GS4, NOTE_FS4,
//NOTE_E4, NOTE_GS4, NOTE_B4, NOTE_CS5, NOTE_CS5, NOTE_B4, NOTE_GS4, NOTE_FS4, 0, NOTE_GS5, NOTE_FS5, NOTE_E5,
// NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_GS5, NOTE_FS5, NOTE_FS5, 0, NOTE_GS5, NOTE_FS5, NOTE_E5, NOTE_E5, NOTE_FS5, NOTE_GS5, 0,
//NOTE_GS5, NOTE_GS5, NOTE_GS5, NOTE_GS5, NOTE_GS5, NOTE_FS5, NOTE_E5,
};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4, 8, 8,
4, 8, 8, 8, 8, 8, 8,
4, 8, 8, 4, 8, 8,
4, 4, 8, 8, 8, 8,
4, 4, 8, 8, 8, 8,
4, 4, 8, 8, 8, 8,
4, 8, 8, 4, 8, 8, 8,
8, 4, 8, 8, 8, 8,
//4, 8, 8, 8, 8, 8, 4, 8, 8, 8, 8, 8, 4, 8, 8, 4, 8, 8,
// 8, 8, 4, 4, 4, 4, 8, 8, 4, 8, 8, 4, 8, 4, 4, 6,
// 4, 8, 8, 4, 8, 8, 6, 8, 8, 8, 8,
// 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 4., 8, 4, 4,
// 8, 8, 8, 8, 6, 6, 6,
};
void setup() {
int thisNote = 0;
int size = sizeof(melody) / sizeof(int);
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
for (int thisNote = 0; thisNote < 8; 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 / noteDurations[thisNote];
tone(8, 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);
noTone(8); // stop the tone playing:
} // end for
}
Song4title();
}]