I've been struggling with sketches that don't compile to use my MP3 shield. I'm new at this.
Does somebody have a sketch that works and can share it?
I've been struggling with sketches that don't compile to use my MP3 shield. I'm new at this.
Does somebody have a sketch that works and can share it?
Sure. Here’s the simplest program I have for a Sparkfun MP3 Shield, which is the Geeetech one anyway.
include <SdFatUtil.h>
#include <SFEMP3Shield.h>
SdFat sd;
SFEMP3Shield MP3player;
void setup() {
Serial.begin(9600);
//start the shield
sd.begin(SD_SEL, SPI_HALF_SPEED);
MP3player.begin();
//start playing track 1
MP3player.playTrack(1);
}
//do something else now
void loop() {
Serial.println("I'm bored!");
delay(2000);
}]
and a more complex one that has a push button trigger and IOT Relay built on:
#include <SPI.h>
//Add the SdFat Libraries
#include <SdFat.h>
#include <SdFatUtil.h>
//and the MP3 Shield Library
#include <SFEMP3Shield.h>
SdFat sd;
SFEMP3Shield MP3player;
int buttonPin = 4; // the number of the pushbutton pin
void setup() {
Serial.begin(9600);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT_PULLUP);
pinMode(10, OUTPUT);
;
//Initialize the MP3 Player Shield and SD card
sd.begin(SD_SEL, SPI_FULL_SPEED);
MP3player.begin();
//start playing track
MP3player.playTrack(1);
}
void loop() {
// put your main code here, to run repeatedly:
int sensorVal = digitalRead(4);
Serial.println(sensorVal);
if (sensorVal == HIGH) { {
Serial.println("on");
// turn relay on:
digitalWrite(10, LOW);
//turn on MP3 player
MP3player.playTrack(1);
delay (9000);
}
} else {
Serial.println("off");
digitalWrite(10, HIGH);
MP3player.stopTrack();
delay (500);
}
}]
You haven’t told us anything other than my code won’t compile, so I’m GUESSING you don’t have the right libraries installed. I know I had to hunt around the web to find a SDFatUtil.h library to go with mine, it never popped up on the IDE Libraries menu.