const int buzzerPin = 7;
void setup() {
// put your setup code here, to run once:
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
playMelody();
}
void playMelody() {
//Define the melody notes and their durations
int melody[] = {262, 294, 330, 349, 392, 440, 494, 523};
int noteDurations[] = {4, 4, 4, 4, 4, 4, 4, 4};
//Play the melody
for (int i = 0; i < 8; i++)
{
tone(buzzerPin, melody[i]);
delay(500 / noteDurations[i]);
noTone(buzzerPin);
delay(50);
}
delay(1000);
}