5 – You might want to play a song of triumph.
The video can be found here
This was super hard for me. I didn’t want to play a song that was already pre-programmed and ready to copy-paste, so I started off with looking up the frequencies of the notes I wanted to play:
This is the chorus of “Firestone” by Kygo. It was hard for me to hear the proper rhythm of the original song, so I just made them all quarter notes. Then, I looked up the frequencies of each note and defined each note with the appropriate frequency:
int melody is the order in which I wanted the notes to play. int tempo is the beat at which I wanted each note to play. I simplified it and made it 4/4 with all quarter notes.
I set the speaker to pin 6, and created a function called sing(), which went in the while loop after the ball was dropped.
The code for “sing()” was found using a website that showed how to create the Super Mario Bros. Theme Song. Other than the actual melody that was played, I used the same structure as the code on this website.
I also set the LED on pin 13 to light up at the beat of the song.