How to connect an MP3 Shield with an LCD and buttons, where the LCD will display what song is playing, and each button is assigned a song

(Previously mentioned in description: How to connect an MP3 Shield with an LCD and buttons, where the LCD will display what song is playing, and each button is assigned a song.)

Code (Also uploaded with Project):

#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
#include <Bounce2.h>
#include <LiquidCrystal.h>

SdFat sd;
SFEMP3Shield MP3player;

/**
* \brief Index of the current track playing.
*
* Value indicates current playing track, used to populate "x" for playing the
* filename of "track00x.mp3" for track000.mp3 through track254.mp3
*/
LiquidCrystal lcd(14, 15, 16, 17, 18, 19);//12, 11, 5, 4, 3, 2
//int8_t current_track = 1;
const int buttonPin = 0;
const int buttonPin1 = 1;
const int buttonPin2 = 5;
const int buttonPin3 = 10;
int buttonState = 0;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
//------------------------------------------------------------------------------
/**
* \brief Setup the Arduino Chip's feature for our use.
*
* After Arduino's kernel has booted initialize basic features for this
* application, such as Serial port and MP3player objects with .begin.
*/
void setup() {
Serial.begin(115200);

lcd.begin(16, 2);
// Print a message to the LCD.

if(!sd.begin(9, SPI_HALF_SPEED)) sd.initErrorHalt();
if (!sd.chdir("/")) sd.errorHalt("sd.chdir");

MP3player.begin();



}


//------------------------------------------------------------------------------
/**
* \brief Main Loop the Arduino Chip
*
* This is called at the end of Arduino kernel's main loop before recycling.
* And is where the user's is executed.
*
* \note If the means of refilling is not interrupt based then the
* MP3player object is serviced with the availaible function.
*/
void loop() {
buttonState = digitalRead(buttonPin);
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
if (buttonState == LOW) {

Serial.println("1");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("S: All You Need ");
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print("Is LoveA:Beetles");
MP3player.stopTrack();
MP3player.playTrack(1);

}

if (buttonState1 == LOW) { 
Serial.println("2");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("S:I'm a Believer");
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print("A: Smash Mouth");
MP3player.stopTrack();
MP3player.playTrack(2);

}

if (buttonState2 == LOW) { 
Serial.println("3");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("S:All Star");
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print("A: Smash Mouth");
MP3player.stopTrack();
MP3player.playTrack(3);

}

if (buttonState3 == LOW) { 
Serial.println("4");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("S:Walkin' On The Sun");
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print("SunA:Smash Mouth");
MP3player.stopTrack();
MP3player.playTrack(4);

}
else{ 

}
}

 

 My code uses songs I put on the SD Card. To use your own songs, put your own MP3 files on an SD card and insert the Sd card into the MP3 Shield from Sparkfun. If you would like your own songs to be displayed on the LCD, change what is being printed to the LCD. You must also obtain the SFEMP3Shield and SD Fat libraries and import them into Arduino. I'm not allowed to post the link to those libraries, so search for them on google. 

Login to post a comment...

andrewgamal 4 years, 2 months ago

don need library

4711engel 4 years, 3 months ago

Where can I download the library SdFatUtil ??