Arduino: Exercise 11

Using the buzzer speaker thingy!

I did the default song, and Ode to Joy. I found a handy list of notes and their frequencies here.

For anyone who wants the code for Ode to Joy:
Plug this into char notes[]:
and this into int beats[]:

I also had to add the low G into the notes (the uppercase G in the notes above if you want to use a different character), the frequency is 196. The tempo I used is 100.

Edit: just wanted to add a little bit of explanation as in the code, it says that a ‘1’ in the beats indicates a quarter note – I made mine so a ‘4’ is a quarter note to allow for eighth notes and sixteenth notes. I didn’t use any sixteenth notes here, but I wanted to keep my options open and methods consistent. I didn’t want to mess around with any variable types (int does not deal with decimals) if I wanted notes shorter than a quarter note. Hence 4 being a quarter note, 1 would be a sixteenth note, etc.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s