Schedule‎ > ‎

Objectives

• Understand how vector insertion works

Read the Scholastic Honesty Policy and Assignment Integrity policies of the syllabus. Here are some clarifications for this particular assignment:

• You must breadboard the circuits yourself, though you may get help from others if you get stuck.
• You may discuss the code with other students for this lab.
• You must enter all the code yourself and not copy from another student.

Part 1:  Music Player cont. (sound_updated.ino)

Using the Music Player setup from Project 7:  (save your new file as sound_updated.ino)

Step 1 :  Adding pauses and note stretches

Look up the Arduino tone() function to understand how it works.

You must take into consideration the special characters (space and '-') when you're playing your melody. Your program will have to keep track of time in order to make the melody sound right. Consider the difference between these two inputs:

`input: aaa `
`produces:`
`  440Hz (190ms) then q``uiet (10ms)   `
`  440Hz (190ms) then q``uiet (10ms)   `` `
`  440Hz (190ms) then q``uiet (10ms)   `` `

`input: a--`
`produces:`
`  440Hz (200ms)`
`  440Hz (200ms)`
`  440Hz (200ms)`

The first plays three distinct "A" notes. The second produces one long "A" note. A space in the input should just play 200ms of silence. When you're ready you can test your program using these melodies:
`Mary Had a Little Lamb: `
`agfgaaa ggg aaa agfgaaaaggagf `

`Yankee Doodle:`
`ffgafag ffgaf-e- ffgaAagfecdef-f-`
Save your file as sound_updated.ino and submit to Canvas.
^ top

Function playNotes  Pseudocode

Loop through array

getNote

if note is a dash  ‘-‘       //keep playing last note 200ms

delay 200ms

if note is a space      // 32 = space  play 200ms silence

stop tone

delay 200ms

if note is  a newline ‘\n’    //end

stop tone

delay 200ms

return

otherwise                           //play the note

turn off last note

delay 10ms

play note

delay 190ms

End of loop through array

Extra Credit (5 pts)

The following are worth extra credit points:

In the sound_updated.ino program, save 5 tunes in an array of `Strings` and allow the user to play the tunes in the array by entering the numbers 1 through 5. (5 points).