I've had a look at the "Random Playback" example at Rogue Robotics, and I think I've hacked it enough to remove the random part! However, now the code merely plays the second last file on the SD card over and over.
There are seven MP3s on the SD card in a directory named "rMP3." I bet its something simple and stupid I'm missing, but any and all help will be appreciated...
void playNextSong()
{
char filename[80];
char path[96];
int i;
if (numberOfSongs > 1) {
filecommands.opendir(directory);
for (i = 0; i <= numberOfSongs; i++) {
filecommands.readdir(filename, "*.mp3");
}
strcpy(path, directory);
strcat(path, "/");
strcat(path, filename);
rmp3.playfile(path);
Serial.print("Playing: ");
Serial.println(path);
}
else {
Serial.println("No files to play.");
}
}
Thats the function for the playing of the files. Now to get it to actually play the file, rather than a second of the file, stop, play again for a second, stop, ad infinitum, I've used this code... but essentially, I want to trigger the playback when the requirements from two sensors are met (a time based one, and a simple HIGH - LOW based one) and when those two requirements aren't met, it eventually stops the file...
void loop()
{
char c;
uint8_t i;
uint8_t lastvolume = 20;
int16_t newtime;
playbackinfo playinfo;
char status = 'S';
uint8_t playing = 1;
uint8_t volume = 20;
uint8_t boostOn = false;
volume = rmp3.getvolume(); // this only gets the left volume
playNextSong();
while(1)
{
while(!Serial.available())
{
// we should do fancy stuff like flash lights on our Xmas tree here!
// got lots of time!
delay(200);
status = rmp3.getplaybackstatus();
playinfo = rmp3.getplaybackinfo();
if (status == 'S' && playing)
playNextSong();
}
}
}
What is it that I'm missing? As I said, its probably something small...