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

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Xian Ruicheng Lab 6

Page history last edited by xinyi xie 9 years, 7 months ago

B-1. Describe the tone pattern you hear (i.e., high or low, how long, etc.).

 

The tone pattern is high, medium, low, and over and over again.

Each is played for a second with pauses of also a second in between.

 

 

C-1. Tell a member of the teaching team what your song is (or better yet, play it for us).

 

The songs preloaded on the SD card are

1. Absolutely Cuckoo — The Magnetic Fields

2. Baba Yetu — Christopher Tin

3. Adiemus — Adiemus

4. Somewhere Over The Rainbow/What A Wonderful World — Israel Kamakawiwo'ole

 

 

C-2. 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?

 

This code only plays .mp3 and .wav song files in the root directory.

The following line in the program prevents text files or other irrelevant files from being "played."

if ((p.name()[i] == 'M' && p.name()[i+1] == 'P' && p.name()[i+2] == '3') ||

(p.name()[i] == 'W' && p.name()[i+1] == 'A' && p.name()[i+2] == 'V')) {

...

}

 

 

C-3. Change the Song (or Simple_MP3_V2) program to save the current volume setting in your EEPROM, then 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.

 

If I want to insert a string at the beginning of the file without over-writing the current contents, I will have to save the current content elsewhere (on the RAM or on the SD card), next SD.remove that file to clear it, and then SD.open with the same file name to create that file again.

Now I can first insert the designated string, and then put the original content that is stored elsewhere back into the file.

#define mp3_vol     175

#define mp3_vol_eepromloc     200  

...

void setup() {

EEPROM.write(mp3_vol_eepromloc, mp3_vol);

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

...

 

 

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

 

Pause Play Button Connection

 

 

D-2. What are the pros and cons of using this method?

 

The pros of using the Bounce object are that it saves the effort for me to write my own method for bounce filtering, and it makes the code more comprehendible and clear, because every setting is given a function.

The cons of using this method are that I have to debug, and spend some time looking into it; and it may take more space when uploading the entire program to the Arduino, since some unused lines of codes are also being copied.

 

 

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

 

#include <Bounce2.h>

...

Bounce debouncer = Bounce(); 

...

 

void setup() {

pinMode(0,INPUT); //the RX pin is connected to the button 

debouncer.attach(0);

debouncer.interval(5);

...

attachInterrupt(2, changePlayerState, CHANGE);

}

 

void changePlayerState() {

debouncer.update();

if (debouncer.read() == HIGH) {

Serial.println("A");

switch(current_state) {

case DIR_PLAY:

current_state = PAUSED;

Mp3.clear_buffer();

break;

case MP3_PLAY:

current_state = PAUSED;

Mp3.clear_buffer();

break;

case PAUSED:

current_state = DIR_PLAY;

break;

}

} 

}

 

 

G-1. Video of my baresbones MP3 player.


 

 

 

G-2. Source code of my barebones MP3 player.

 

 

 

 

Comments (1)

xinyi xie said

at 11:43 pm on Aug 16, 2014

Great job!

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