#define buzzer 10
void setup() {
pinMode(buzzer, OUTPUT);
}
void loop() {
HappyBirthdayMelody();
delay(2000);
}
void HappyBirthdayMelody() {
int melody[] = { 262, 262, 294, 262, 349, 330, 262, 262, 294, 262, 392, 349,
262, 262, 523, 440, 349, 330, 294, 466, 466, 440, 349, 392, 349};
int noteDurations[] = { 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4,
2, 4, 4, 4, 4, 4, 2};
for (int i = 0; i < 26; i++) {
int noteDuration = 1000 / noteDurations[i];
tone(buzzer, melody[i], noteDuration);
delay(noteDuration * 1.3);
noTone(buzzer);
delay(50);
}
}