// กำหนดพอร์ต GPIO ที่เชื่อมต่อกับ Buzzer
int buzzerPin = 25; // เปลี่ยนตามพอร์ตที่ใช้เชื่อมต่อ
// กำหนดโน้ตเสียง (Hz)
int note_C4 = 262; // โน้ต C4
int note_D4 = 294; // โน้ต D4
int note_E4 = 330; // โน้ต E4
int note_F4 = 349; // โน้ต F4
int note_G4 = 392; // โน้ต G4
int note_A4 = 440; // โน้ต A4
int note_B4 = 494; // โน้ต B4
int note_C5 = 523; // โน้ต C5
int note_D5 = 587; // โน้ต D5
int note_E5 = 659; // โน้ต E5
int note_F5 = 698; // โน้ต F5
int note_G5 = 784; // โน้ต G5
int note_A5 = 880; // โน้ต A5
int note_B5 = 988; // โน้ต B5
// ความยาวของโน้ต (เวลาในการเล่น)
int wholeNote = 1000; // 1 whole note = 1000 ms
int halfNote = wholeNote / 2; // ครึ่งโน้ต
int quarterNote = wholeNote / 4; // โน้ตหนึ่งในสี่
int eighthNote = wholeNote / 8; // โน้ตแปด
int sixteenthNote = wholeNote / 16; // โน้ตสิบหก
int dottedQuarterNote = wholeNote * 3 / 8; // โน้ตหนึ่งในสี่ที่มีจุด (เพิ่มระยะเวลา)
void setup() {
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// เพลง Opening Credits | Game of Thrones
tone(buzzerPin, note_G4, halfNote); // G4
delay(halfNote);
tone(buzzerPin, note_C5, quarterNote); // C5
delay(quarterNote);
tone(buzzerPin, note_D5, quarterNote); // D5
delay(quarterNote);
tone(buzzerPin, note_G4, quarterNote); // G4
delay(quarterNote);
tone(buzzerPin, note_D5, quarterNote); // D5
delay(quarterNote);
tone(buzzerPin, note_E5, halfNote); // E5
delay(halfNote);
tone(buzzerPin, note_F5, quarterNote); // F5
delay(quarterNote);
tone(buzzerPin, note_G5, quarterNote); // G5
delay(quarterNote);
tone(buzzerPin, note_F5, eighthNote); // F5
delay(eighthNote);
tone(buzzerPin, note_E5, eighthNote); // E5
delay(eighthNote);
tone(buzzerPin, note_D5, quarterNote); // D5
delay(quarterNote);
tone(buzzerPin, note_C5, quarterNote); // C5
delay(quarterNote);
tone(buzzerPin, note_G4, halfNote); // G4
delay(halfNote);
// ท่อนซ้ำและเพิ่มรายละเอียด
tone(buzzerPin, note_G4, halfNote); // G4
delay(halfNote);
tone(buzzerPin, note_C5, quarterNote); // C5
delay(quarterNote);
tone(buzzerPin, note_D5, quarterNote); // D5
delay(quarterNote);
tone(buzzerPin, note_G4, quarterNote); // G4
delay(quarterNote);
tone(buzzerPin, note_D5, quarterNote); // D5
delay(quarterNote);
tone(buzzerPin, note_E5, halfNote); // E5
delay(halfNote);
tone(buzzerPin, note_F5, quarterNote); // F5
delay(quarterNote);
tone(buzzerPin, note_G5, quarterNote); // G5
delay(quarterNote);
tone(buzzerPin, note_A5, quarterNote); // A5
delay(quarterNote);
tone(buzzerPin, note_B5, quarterNote); // B5
delay(quarterNote);
tone(buzzerPin, note_A5, quarterNote); // A5
delay(quarterNote);
tone(buzzerPin, note_G5, quarterNote); // G5
delay(quarterNote);
tone(buzzerPin, note_F5, quarterNote); // F5
delay(quarterNote);
tone(buzzerPin, note_E5, quarterNote); // E5
delay(quarterNote);
tone(buzzerPin, note_D5, halfNote); // D5
delay(halfNote);
tone(buzzerPin, note_C5, quarterNote); // C5
delay(quarterNote);
tone(buzzerPin, note_G4, halfNote); // G4
delay(halfNote);
// รอระยะเวลาเล็กน้อยก่อนเริ่มใหม่
delay(2000);
}