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

  • Social distancing? Try a better way to work remotely on your online files. Dokkio, a new product from PBworks, can help your team find, organize, and collaborate on your Drive, Gmail, Dropbox, Box, and Slack files. Sign up for free.

View
 

LAB 6- MAURA

Page history last edited by mauraaz@... 6 years, 11 months ago

(No questions on part A.)

 

PART B

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

I hear three tones, separated by a pause. The second one is lower than the first, and the third is highest.

 

 

PART C

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

Mahna Mahna by the Muppets

 

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?

Yes- it would play all songs on the SD card. It does not play the text file because it checks the ending of the file and only plays those ending in .MP3 or .WMV.

 

Change the 'Simple_MP3_V2' 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. 

add the following:

EEPROM.write(max_num_songs*max_name_len, mp3_vol);

myVS.setVolume(mp3_vol);

 

PART D

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

 

 

What are the pros and cons of using this method?

The advantages is that the code is simple and does a good job of letting us distinguish when a button is pressed from the noise that follows this signal. The disadvantage, however, is that it does not work well if the button is pressed again too soon thereafter.

 

 

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

 

/*

 * example sketch to play audio file(s) in a directory, using the VS1053 library

 * for playback and the arduino sd library to read files from a microsd card.

 * pins are setup to work well for Arduino Micro.

 * 

 * originally based on frank zhao's player: http://frank.circleofcurrent.com/

 * utilities adapted from previous versions of the functions by matthew seal.

 *

 * (c) 2011, 2012 david sirkin sirkin@cdr.stanford.edu

 *                akil srinivasan akils@stanford.edu

 */

 

#include <SPI.h>

#include <SD.h> b

#include <EEPROM.h>

#include <VS1053.h>

 

#include <Adafruit_GFX.h>

#include <Adafruit_PCD8544.h>

 

#define max_title_len 60

#define max_name_len  13

#define max_num_songs 40

 

#define read_buffer  256

#define mp3_vol      175

 

#define sd_cs         17

 

VS1053 myVS(A0, A1, A2, -1);

Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, -1 ,4);

 

File sd_file;

 

unsigned char num_songs = 0, current_song = 0;

 

char fn[max_name_len];

 

char title[max_title_len + 1];

 

enum state { DIR_PLAY, MP3_PLAY, PAUSED };

state current_state = DIR_PLAY;

 

 

void setup()

{

  SPI.begin();

  myVS.begin();

  display.begin();

 

  display.setContrast(50);

  display.clearDisplay();

  display.setCursor(0,0);

  display.print("Barebones Mp3!");

  display.display();

  delay(2000);

 

  sd_card_setup();

  sd_dir_setup();

  while (num_songs==0) {

    display.clearDisplay();

    display.println("No songs on");

    display.print("card!");   

    display.display();

    delay(5000);

  }

  openSongFile(current_song);

  song_title_to_display();

 

  attachInterrupt(0, pause, LOW);

}

 

void dir_play() {

  if (sd_file) {

    mp3_play();

  }

  else {

    // since 'sd_file' isn't open, the recently playing song must have ended.

    // increment the index, and open the next song, unless it's the last song

    // in the directory. in that case, just set the state to PAUSED.

    if (current_song < (num_songs - 1)) {

      current_song++;

      openSongFile(current_song);

      song_title_to_display();

      myVS.startSong();

    }

    else {

      current_state = PAUSED;

    }

  }

}  

 

void mp3_play() {

  unsigned char bytes[read_buffer]; // buffer to read and send to the decoder

  unsigned int bytes_to_read;       // number of bytes read from microsd card

 

  // first fill the 'bytes' buffer with (up to) 'read_buffer' count of bytes.

  // that happens through the 'sd_file.read()' call, which returns the actual

  // number of bytes that were read (which can be fewer than 'read_buffer' if

  // at the end of the file). then send the retrieved bytes out to be played.

 

  // 'sd_file.read()' manages the index pointer into the file and knows where

  // to start reading the next batch of bytes. 'Mp3.play()' manages the index

  // pointer into the 'bytes' buffer and knows how to send it to the decoder.

 

  bytes_to_read = sd_file.read(bytes, read_buffer);

  myVS.playChunk(bytes, bytes_to_read);

 

  // 'bytes_to_read' is only smaller than 'read_buffer' when the song's over.

 

  if (bytes_to_read < read_buffer) {

    sd_file.close();

    myVS.stopSong();

 

    // if we've been in the MP3_PLAY state, then we want to pause the player.

    if (current_state == MP3_PLAY) {

      current_state == PAUSED;

    }

  }

}

 

void loop()

{

  switch(current_state) {

 

    case DIR_PLAY:

      dir_play();

      break;

 

    case MP3_PLAY:

      mp3_play();

      break;

 

    case PAUSED:

      break;

  }

}

 

 

void pause()

{

  static unsigned long last_interrupt_time = 0;

  unsigned long interrupt_time = millis();

  if (interrupt_time - last_interrupt_time > 200)

   {

  if(current_state == DIR_PLAY){

  current_state = PAUSED;

  }

  else if (current_state == PAUSED){

    current_state = DIR_PLAY;

  }

  }

  last_interrupt_time = interrupt_time;

}

 

 

 

 

 

 

Comments (0)

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