Game of Thrones Theme on Arduino

Here’s the Game of Throne‘s Theme on the Arduino. Pretty self-explanatory.


Right now the code is:

int melody[] = {
NOTE_G3 , NOTE_C3, NOTE_DS3, NOTE_F3, NOTE_G3 ,NOTE_C3, NOTE_DS3, NOTE_F3, NOTE_D3,
NOTE_F3 , NOTE_B2, NOTE_D3, NOTE_DS3, NOTE_F3, NOTE_B2, NOTE_DS3, NOTE_D3,NOTE_C3 };
int noteDurations[] = {
3, 3, 1, 1, 2, 2, 1, 1, 9,
3, 3, 1, 1, 2, 2, 1, 1, 9};

void setup() {
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 18; thisNote++) {

// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 300 * noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);

//pause for the note’s duration plus 30 ms:
delay(noteDuration +30);
}
}

void loop() {
// no need to repeat the melody.
}

Next steps would be writing a function that parses out note using this formula that converts intervals from a4 into Hertz:

f = 440 × 2((n−58)/12)

← Previous post

Next post →

1 Comment

  1. Benedetta

    Very cool! Loved it! B_

Leave a Reply to Benedetta Cancel reply