#define BUZZER_PIN 12
// Notes and their corresponding frequencies in Hz
#define NOTE_C4 262
#define NOTE_D4 294
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_G4 392
#define NOTE_A4 440
#define NOTE_B4 494
#define NOTE_C5 523
// Melody of the Interstellar theme (simplified)
int melody[] = {
NOTE_C4, NOTE_E4, NOTE_F4, NOTE_C5,
NOTE_E4, NOTE_F4, NOTE_C5, NOTE_E4,
NOTE_C4, NOTE_E4, NOTE_F4, NOTE_G4,
NOTE_C5, NOTE_E4, NOTE_F4, NOTE_C4
};
// Note durations: 4 = quarter note, 8 = eighth note, etc.
int noteDurations[] = {
4, 4, 4, 4,
4, 4, 4, 4,
4, 4, 4, 4,
4, 4, 4, 4
};
void setup() {
// no setup required for this code
}
void loop() {
for (int thisNote = 0; thisNote < sizeof(melody)/sizeof(melody[0]); thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];
tone(BUZZER_PIN, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(BUZZER_PIN);
}
// Add a pause before repeating the melody
delay(1000);
}