#include <Tone.h>
Tone tone1;
int melody[] = {
NOTE_C5, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, 0, NOTE_B4, NOTE_C5
};
// Durasi dalam milidetik
int noteDurations[] = {
500, 250, 250, 500, 500, 500, 500, 500
};
void setup() {
tone1.begin(8); // Inisialisasi Tone pada pin 8
Serial.begin(9600); // Inisialisasi serial monitor
}
void loop() {
for (int thisNote = 0; thisNote < 8; thisNote++) {
Serial.print("Playing note: ");
Serial.println(melody[thisNote]);
tone1.play(melody[thisNote], noteDurations[thisNote]);
delay(noteDurations[thisNote]);
}
}