#define buzzer 7
#define led 8
int melody[] = {
2637, 2637, 0, 2637,
0, 2093, 2637, 0,
3136, 0, 0, 0,
1568, 0, 0, 0,
2093, 0, 0, 1568,
0, 0, 1319, 0,
0, 1760, 0, 1976,
0, 1865, 1760, 0,
1568, 2637, 3136,
3520, 0, 2794, 3136,
0, 2637, 0, 2093,
2349, 1976, 0, 0
};
int noteDurations[] = {
12, 12, 12, 12,
12, 12, 12, 12,
9, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
9, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12
};
void setup() {
pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
}
void loop() {
for (int i = 0; i < sizeof(melody) / sizeof(int); i++) {
int duration = 1000 / noteDurations[i];
tone(buzzer, melody[i], duration);
digitalWrite(led, HIGH);
delay(duration * 1.3);
noTone(buzzer);
digitalWrite(led, LOW);
delay(duration * 1.3);
}
}