const int buzzerPin = 8;
int melody[] = {
264, 264, 297, 264, 352, 330, // Selamat ulang tahun
264, 264, 297, 264, 396, 352, // Selamat ulang tahun
264, 264, 528, 440, 352, 330, 297, // Selamat panjang umur
466, 466, 440, 352, 396, 352 // Kita 'kan doakan
};
int noteDurations[] = {
4, 4, 2, 2, 2, 1,
4, 4, 2, 2, 2, 1,
4, 4, 2, 2, 2, 2, 1,
4, 4, 2, 2, 2, 1
};
void setup() {
// tidak diperlukan
}
void loop() {
int length = sizeof(melody) / sizeof(melody[0]);
for (int thisNote = 0; thisNote < length; thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];
tone(buzzerPin, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(buzzerPin);
}
delay(1000); // jeda antar pengulangan lagu
}