First of all, thanks for the reply.
- Doesn't look like a LOW to me.
I'm aware of that, just did it for testing
That's right. You do NOTHING in loop(). Not a thing. Make setup() play the track. Do not add any more code until you know that the hardware is working.
Allright, so de code should look something like this?
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
SFEMP3Shield MP3player;
SdFat sd;
int8_t current_track = 0;
const int buttonPin = 0;
unsigned long playTime = 120000; // how long a file will play in milliseconds (15000=15 seconds)
unsigned long pauseTime = 5000; // how long the pause will be after the sound ends (10000=10 seconds)
int readingInterval = 500; // how often to read the sensor
// changing variables
unsigned long currentMillis = 0; // time variable to track running time: current time
unsigned long startingMillis = 0; // time variable to track running time: starting time
// setup
void setup() {
Serial.begin(115200);
pinMode(buttonPin, INPUT);
MP3player.begin();
MP3player.playTrack(1);
MP3player.setVolume(10, 10);
Serial.println(F(""));
if (digitalRead(buttonPin)== LOW) {
Serial.print(F());
Serial.println();
MP3player.playTrack();
playtime();
MP3player.stopTrack();
delay(pauseTime);
}
delay(readingInterval);
}
void playtime() {
startingMillis = millis(); // set both time counter
currentMillis = millis();
while ( currentMillis - startingMillis < playTime ) { // while track plays, runs until playTime is reached
currentMillis = millis(); // set to actual time
delay(5); // debounce
}
}
void loop(){ }