Arduino Song Player

This assignment will require each of you to write an Arduino program to play “Are You Sleeping, Brother John” at 90 bpm using the speaker from your Arduino kit.  It will need to start on Pin 10 going LOW and set Pin 13 LOW after 8 beats.  This will allow us to wire multiple Arduinos together to play the song in a “round” automatically.  An example program is provided below to use as a starting point for your program.

For your initial assignment, due Monday Oct. 21 before class starts, your program will need to:

  1. play “Are You Sleeping, Brother John” using the speaker from your Arduino kit connected to Pin 8.
  2. play the song  at 90 bpm.
  3. start playing the song when Pin 10 goes LOW and play it again if Pin 10 is still LOW after song completes.
  4. set Pin 13 LOW after 8 beats of the song (on the start of the 9th beat)
  5. set Pin 13 back to HIGH at the end of each verse.

For your second assignment, due Wednesday Oct. 30 by midnight, alter your program from the first assignment in the following way:

  1. play the song using a for loop to step through the elements of two arrays containing the note values of the song (noteVal[]) and the note lengths (noteLen[]).  Each time through the loop you should play the next note in the array noteVal[] and delay for the number of milliseconds in the corresponding element of array noteLen[].  The necessary arrays are already defined in the example program.  Use the value provided in noteCnt as the loop limit.  The version you hand in for this assignment should sound identical to the version from the first assignment.  The only difference is that this version is implemented using a loop and the first version is not.    An example program is provided below to use as a starting point for your program.

For extra credit, implement the following:

  1. use the value read from a potentiometer to adjust the playback speed of the song between 80 and 100 bpm. So a minimum reading of zero from the potentiometer should correspond to a playback speed of 80 bpm, and a maximum reading of 1023 from the potentiometer should correspond to 100 bpm.  Intermediate values from the pot should scale playback speed linearly between 80 and 100 bpm.

You are encouraged to use the class Forum on this web site to discuss this assignment and ask questions of the instructor and your fellow students.

Code to start for first assignment:   playRUSleeping_ex1

Solution to first assignment:   noloopRUSleeping

Code to start for second assignment:   loopRUSleeping_ex

Print This Page