Final Project EE47 (1)


Thomas Che

EE47 Final Project Documentation – BOOMBOX mini

Design Vision/Point of View:

My design was created based on the fact that size would amount to the time it would take to create it. So I thought of a player of music that would be excusable for the size it might become, so I immediately was draw to a Boom box. With this idea and the parts I had, I imagined a miniature sized boom box of which I could hook onto my backpack or onto my belt loop, and still be able to blast music at its loudest. The idea was to make a more portable version of a Boom box that allowed to download any music you wanted into it, without the necessity of CD’s or cassettes, and you could also plug in headphones or ear buds in to listen to the music yourself!

I envisioned the Boom box mini with the classic two loudspeakers with a display in the middle that would display the selected song. There would also be a large button of which to play and stop the song, an encoder which would scroll through the songs, and a potentiometer that could adjust the volume.

BOOMBOX mini Preliminary Plan (Right):

BOOMBOX mini paper Prototype (Left):

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Components Necessary:

Process:

Because the week leading up to the final presentation was Finals week, the process of constructing my project was very hectic. On Monday, I focused on building the face of the Boom box using the laser cutting in Room 36, and I completed the face as planned. On Tuesday I was busy with Finals from another class, and on Wednesday was spent in vain trying to utilize another mp3 decoder that I bought from Adafruit. When I realized that it was not working out I spent Thursday rewiring the previous mp3 circuit that we learned in lab 6, and wired up the loudspeakers to the amplifier to the mp3. On Friday, I managed to get the Play and Pause button working. However, I did not managed my time wisely and I didn’t not get to the other functions of the BOOMBOX mini that I wanted to implement such as the display, the song selector, and the volume knob. I decided to focus on the basic parts of the mp3 such as getting it to play music in the first play and controller when to play the music.

Project Code:

// ---- includes and defines ------------------------------------------------

 

const int ledPin = 9;

#include <SD.h>

#include <SPI.h>

#include <EEPROM.h>

#include <mp3.h>

#include <mp3conf.h>

#include <Adafruit_GFX.h>

#include <Adafruit_PCD8544.h>

#define sd_cs 17

#define mp3_cs A0

#define mp3_dcs A1

#define mp3_rst -1

#define mp3_dreq A2

#define lcd_dc A4

#define lcd_cs A3

#define lcd_rst -1

#define read_buffer 512

#define mp3_vol 254

#define max_name_len 13

#define max_num_songs 40

#define max_title_len 60

 

// ---- global variables ----------------------------------------------------

 

Adafruit_PCD8544 lcd = Adafruit_PCD8544(lcd_dc, lcd_cs, lcd_rst);

 

 

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 = PAUSED;

 

//---- module functions -----------------------------------------------------

 

void pause() {

if (current_state != PAUSED) {

current_state = PAUSED;

}

else {

current_state = DIR_PLAY;

}

}

 

void my_interrupt_handler() {

static unsigned long last_interrupt_time = 0;

unsigned long interrupt_time = millis();

if (interrupt_time - last_interrupt_time > 200) {

pause();

}

last_interrupt_time = interrupt_time;

}

 

void sd_file_open() {

get_current_song_as_fn();

sd_file = SD.open(fn, FILE_READ);

print_title_to_lcd();

}

 

void mp3_play() {

unsigned char bytes[read_buffer];

unsigned int bytes_to_read;

bytes_to_read = sd_file.read(bytes, read_buffer);

Mp3.play(bytes, bytes_to_read);

if (bytes_to_read < read_buffer) {

sd_file.close();

if (current_state == MP3_PLAY) {

current_state == PAUSED;

}

}

}

void dir_play() {

if (sd_file) {

mp3_play();

}

else {

if (current_song < (num_songs - 1)) {

current_song++;

sd_file_open();

}

else {

current_state = PAUSED;

}

}

}

 

// ---- setup and loop ------------------------------------------------------

 

void setup() {

pinMode(ledPin, OUTPUT);

lcd.begin(55);

lcd.display();

delay(500);

lcd.clearDisplay();

lcd.print("Barebones Mp3!");

lcd.display();

delay(500);

Mp3.begin(mp3_cs, mp3_dcs, mp3_rst, mp3_dreq);

Mp3.volume(mp3_vol);

sd_card_setup();

sd_dir_setup();

sd_file_open();

}

 

void loop() {

digitalWrite(ledPin, HIGH);

if(digitalRead(3) == LOW) {

my_interrupt_handler();

}

switch(current_state) {

case DIR_PLAY:

dir_play();

break;

case MP3_PLAY:

mp3_play();

break;

case PAUSED:

break;

}

}

Video of Final Project:

https://www.youtube.com/watch?v=catCrEWisWQ&feature=youtu.be