// Define the notes and their corresponding durations
int melody[] = {
NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4,
// Add more notes as needed
};
// Define the note durations: 4 = quarter note, 8 = eighth note, etc.
int noteDurations[] = {
4, 4, 4, 4, 4, 4, 4,
// Adjust the durations as needed
};
void setup() {
// Set the buzzer pin as an OUTPUT
pinMode(8, OUTPUT);
}
void loop() {
// Iterate through the melody and play each note
for (int i = 0; i < sizeof(melody) / sizeof(melody[0]); i++) {
int noteDuration = 1000 / noteDurations[i];
tone(8, melody[i], noteDuration);
// Add a brief delay between notes
delay(noteDuration * 1.1);
// Stop the tone to create a pause between notes
noTone(8);
}
// Add a longer pause between verses
delay(1000);
}