The set up is pretty simple. Notice that the piezo uses a PWM pin. This is because the change in power is what causes the change in tone.
This code is very similar to the one from the previous project. One difference is that the speaker has more attributes: song, beats, and tempo.
I used the notes from this song for the “song” attribute, with a dash placed between each one in order to get a pause between the notes. I used an 1/8th beat, so in the cod,e one letter under the “song” attribute would play for 1/8th of a beat. Longer notes, like a quarter, are represented by two letters next to each other without a dash in between, and so on.