| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

Pranav Rajpurkar_Lab6

Page history last edited by Benjamin Tee 9 years, 2 months ago

Barebones MP3 Player – Pranav Rajpurkar

 

Part B - Connect and Test your Decoder

 

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

There are 3 different notes, a high pitch, a middle pitch and a low pitch. Each note is for about 2 seconds and there is a 1s pause between the notes.

 

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.

It’s from the Muppets, called Mah na Mah na.

 

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 the songs with the extensions .wav or .mp3. It skips files with the extension .txt. It plays songs only in the main directory of the SD card.

 

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_FILE_COUNT*MAX_NAME_LENGTH (in this case, 520) bytes of the EEPROM are used to store file names, so don't overwrite those.

 

//declare a variable called songVol

int songVol = 1023;

//check if mp3 volume is same as EEPROM volume 

if(EEPROM.read(songVol) != mp3_vol){

//if not equal, write it

    EEPROM.write(songVol, mp3_vol);

  }else{

//if equal, then read it

    Mp3.volume(EEPROM.read(songVol));

}


 Part D. Pause to Learn About Interrupts

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

 

Taken from lab 2. 

 

What are the pros and cons of using this method?

Pros - allows us to read different states like rising edge, falling edge and change.

Cons - It's not compatible with interrupts.  Still using delay which slows down program.

 

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

 

volatile int isPlaying = HIGH;

void setup(){

attachInterrupt(1, playPause, LOW);

  }

void playPause(){

  static unsigned long last_interrupt_time = 0;

  unsigned long interrupt_time = millis();

   if (interrupt_time - last_interrupt_time > 200)    {

     if(isPlaying ==HIGH){

      isPlaying = LOW;

      } else{

      isPlaying= HIGH;

    }

  }

  last_interrupt_time = interrupt_time;

}

 

 

void mp3_play (SdFile *file) {

do {

 if(isPlaying==HIGH ){

    bytes_to_read = file->read(bytes, read_buffer);

    Mp3.play(bytes, bytes_to_read);

  }

 }

  while (bytes_to_read == read_buffer);

}




 

Comments (0)

You don't have permission to comment on this page.