The project is to use one push button to make a sparkfun mp3 shield cycle through tracks one at a time. I was wondering if anyone had any ideas on how to do this or the direction that I could go. I have tried a few different options, and am now doubting the possibility of it working. This is the code I have been working with. The problem I think I am having is that the source code requires a 0 before the track number but I don't know how to get that padded 0 there from the bush button.
#include <SPI.h> //bus SPI
#include <SdFat.h> //SD card
#include <SdFatUtil.h> //SD card tools
#include <SFEMP3Shield.h> //shield library
SFEMP3Shield MP3player; //player
SdFat sd; //card
const int pinButton = 5;
const int nbTracks = 5; //CHANGE THIS VALUE TO THE NUMBER OF SONGS ON YOUR SD CARD
const int volume = 2;//-3dB. The higher number, the lower volume
int counter = 01;
void setup() {
Serial.begin(9600);
sd.begin(SD_SEL, SPI_HALF_SPEED); //start card
pinMode(pinButton, INPUT);
//setup of player
MP3player.begin(); //start player
MP3player.setDifferentialOutput(1); //higher output power
MP3player.setVolume(volume, volume);
}
void loop(){
if (MP3player.isPlaying() && digitalRead(pinButton)){
//if playing, then a press of the button stops the music
MP3player.stopTrack();
Serial.println("music stopped");
delay(500); //to release button
}
else if(!MP3player.isPlaying() && digitalRead(pinButton)){
//if not playing, then a press of the button starts the music
//first, increment counter
counter += 1;
if (counter > nbTracks)
counter = 1;
int errorCode; //used to debug
errorCode = MP3player.playTrack(counter); //play
Serial.print("playing track ");
Serial.print(counter);
Serial.print(" at ");
Serial.print(-volume/2);
Serial.println("dB");
Serial.print("error code (0 is OK): ");
Serial.println(errorCode);
delay(500); //to release button
}
}