Skip to content

Instantly share code, notes, and snippets.

@microtherion
Created July 31, 2014 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save microtherion/194b92549496616eb649 to your computer and use it in GitHub Desktop.
Save microtherion/194b92549496616eb649 to your computer and use it in GitHub Desktop.
#include <SPI.h>
//Add the SdFat Libraries
#include <SdFat.h>
#include <SdFatUtil.h>
//and the MP3 Shield Library
#include <SFEMP3Shield.h>
/**
* \brief Object instancing the SdFat library.
*
* principal object for handling all SdCard functions.
*/
SdFat sd;
//create and name the library object
SFEMP3Shield MP3player;
byte temp;
byte result;
char title[30];
char artist[30];
char album[30];
void setup() {
Serial.begin(9600);
//Initialize the SdCard.
if(!sd.begin(SD_SEL, SPI_FULL_SPEED)) sd.initErrorHalt();
// depending upon your SdCard environment, SPI_HAVE_SPEED may work better.
if(!sd.chdir("/")) sd.errorHalt("sd.chdir");
//boot up the MP3 Player Shield
result = MP3player.begin();
//check result, see readme for error codes.
if(result != 0) {
Serial.print("Error code: ");
Serial.print(result);
Serial.println(" when trying to start MP3 player");
}
pinMode(A0, INPUT_PULLUP);
MP3player.setVolume(2, 2);
}
void loop() {
while (digitalRead(A0))
delay(10);
//tell the MP3 Shield to play a track
result = MP3player.playTrack(3);
Serial.println("Go!\n");
//check result, see readme for error codes.
if(result != 0) {
Serial.print("Error code: ");
Serial.print(result);
Serial.println(" when trying to play track");
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment