rMP3 Sequential Playback

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...

So do you actually want to play the files in order or do you want to be able to select a file to play?

I think you're missing the important bit of code there.

How is 'number of songs' declared?

I have got an rMP3 and have used that example but it is a while since I have played with it...

Mowcius

Mowcius

Thanks for the reply.

I'd like to play the files in order, then once the last song has played, I'd like it to loop back to the first song.

The variable "numberOfSongs" is obtained by the following command:

numberOfSongs = filecommands.filecount(path);

This command is in the setup portion of the program. The reason I didn't post it was because I didn't want to dump my whole program in, and have everyone wade through it.

Do you need any more information?

I'm afraid I'm not sure.

I will nudge Brett this way.

Mowcius

Thanks Mowcius!

I think I get what you're trying to do. I wrote some code that should accomplish what you're looking for. You'll have to add your function for the trigger.

http://www.roguerobotics.com/wikidocs/code/rmp3_trigger_with_time-out_example

b

Rogue Robotics