Lab 6 - Cam Bennett


Barebones MP3 Player

 

 

 

Part B. Connect And Test Your Decoder

Describe the tone pattern you hear (ie, high or low?  how long? etc)

Three notes, from high to low, play over and over. Each lasts a second and there is a second pause in between.

 

Part C. Play Some Music!

Tell a member of the teaching team what your song is (or better yet, play it for us). If you don't know the name, just decipher some of the lyrics.

 

1) You just need a little bit of tending to, let me show you what a little bit of love can do

2) one of those robert plant/allison kraus compilations

3) absolutely cuckoo

 

Does this code play all the songs in all the directories of the SD card? If not, which songs does it play? How does it keep from playing the text file?

 

It plays all 3 songs, then stops. To ensure that the text file is never played, the code searches the file name for the '.', then checks the next three characters to make sure the extension is either MP3 or WAV.

 

Change the 'song' code to save the current volume setting in your EEPROM and fetch and set that value during initialization.  Note that the first max_num_songs*max_name_len (in this case, 520) bytes of the EEPROM are used to store file names, so don't overwrite those. 

to save:

EEPROM.write(max_num_songs*max_name_len, mp3_vol);

 

at initialization: 

 

Mp3.volume(EEPROM.read(max_num_songs*max_name_len));

 

 

Part D. Pause to Learn About Interrupts

 

What if you want to play or stop playing a song on command?

 

The Teensy has 4 pins with external interrupts built in, on pins 5, 6, 7 and 8 (which correspond with interrupt 0, 1, 2, and 3 respectively). You can use them by using the attachInterrupt() function, which is part of the extended Arduino language.

 

Try the sample code from the attachInterrupt reference page with a button circuit that is tied high with a 10K resistor and that gets pulled to ground when the button is depressed.

 

In general (as in the sample code), when you set or change a variable within an interrupt service routine (ISR), you should declare that variable as volatile, to tell the compiler to load its value from RAM instead of storing it in a register to optimize.

 

Draw us a quick sketch of what your circuit looks like.

 


V - Resistor - Switch - Ground

                         -

                         Input

 

What happens when you press the button? What happens when you press the button 15 times in a row?

 

To debounce the button in software, you can create a "bouncer" object that waits a bit before reading the button:

http://www.arduino.cc/playground/Code/Bounce

 

What are the pros and cons of using this method?

Pro: No bouncing

 

Con: the bouncer has to be continually updated in the loop function;

Now, take what you learned to make an interrupt driven pause function for your Barebones MP3 player!