#include "pitches.h"
// Define the buzzer pin
const int buzzerPin = 23;
// Define the duration of each note (in milliseconds)
const int noteDuration = 1000;
// Define the melody (adjust as needed)
int melody[] = {
NOTE_C4, NOTE_E4, NOTE_G4, NOTE_C5,
NOTE_G4, NOTE_E4, NOTE_C4, NOTE_G4,
NOTE_C4, NOTE_E4, NOTE_G4, NOTE_C5,
NOTE_G4, NOTE_E4, NOTE_C4, NOTE_G4
};
// Define the rest value
const int REST = 0;
void setup() {
// Set the buzzer pin as an output
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// Iterate through the melody and play each note
for (int i = 0; i < sizeof(melody) / sizeof(melody[0]); i++) {
// Calculate the note duration
int duration = noteDuration;
// If the note is a rest, pause for the calculated duration
if (melody[i] == REST) {
delay(duration);
} else {
// Play the note on the buzzer
tone(buzzerPin, melody[i], duration);
// Pause for a short time between notes
delay(50);
}
}
// Pause for 60 seconds
delay(60000);
}