Hello, I'm using this MP3 Shield Trigger code that runs different mp3 tracks base on the button you push. It works OK but every time a track ends it won't start unless 1. I push the stop button 2. I play another track (which starts with no problem) . When I push some other button the tracks switch with no problem so its basically a problem with the way the track ends in the code. I was wondering how to change the code so it will allow the same track to be played again even if it is the same track that was the last one to be playing. thank you!
/*
MP3 Shield Trigger
by: Jim Lindblom
SparkFun Electronics
date: September 23, 2013
This is an example MP3 trigger sketch for the SparkFun MP3 Shield.
Pins 0, 1, 5, 10, A0, A1, A2, A3, and A4 are setup to trigger tracks
"track001.mp3", "track002.mp3", etc. on an SD card loaded into
the shield. Whenever any of those pins are shorted to ground,
their respective track will start playing.
When a new pin is triggered, any track currently playing will
stop, and the new one will start.
A5 is setup to globally STOP playing a track when triggered.
If you need more triggers, the shield's jumpers on pins 3 and 4
(MIDI-IN and GPIO1) can be cut open and used as additional
trigger pins. Also, because pins 0 and 1 are used as triggers
Serial is not available for debugging. Disable those as
triggers if you want to use serial.
Much of this code was grabbed from the FilePlayer example
included with the SFEMP3Shield library. Major thanks to Bill
Porter and Michael Flaga, again, for this amazing library!
*/
#include // SPI library
#include // SDFat Library
#include // SDFat Util Library
#include // Mp3 Shield Library
SdFat sd; // Create object to handle SD functions
SFEMP3Shield MP3player; // Create Mp3 library object
// These variables are used in the MP3 initialization to set up
// some stereo options:
const uint8_t volume = 0; // MP3 Player volume 0=max, 255=lowest (off)
const uint16_t monoMode = 1; // Mono setting 0=off, 3=max
/* Pin setup */
#define TRIGGER_COUNT 9
int triggerPins[TRIGGER_COUNT] = {0, 1, 5, 10, A0, A1, A2, A3, A4};
int stopPin = A5; // This pin triggers a track stop.
int lastTrigger = 0; // This variable keeps track of which tune is playing
void setup()
{
/* Set up all trigger pins as inputs, with pull-ups activated: */
for (int i=0; i