I could use some help - Need a random MP3 file to play 1/10 short bursts of sound files every 1 second generating a random number in an while loop ??
I'm using a MP3 Uno Sheild .
I have x10 MP3s on a SD . 1.mp3, 2.mp3, 4 .mp3 .
I'm using the code* below, and it's only playing the single 1.mp3
*@Grumpy_Mike wrote the original code (thankyou)
long indexToWrite;
char toPlay[11]; //
// function makeName
void makeName(int number, int depth){ // generates a file name 0.mp3 to 9999.mp3 suppressing leading zeros
if(number > 9) {
makeName(number / 10, ++depth); // recursion
depth--;
number = number % 10; // only have to deal with the next significant digit of the number
}
toPlay[indexToWrite] = (number & 0xf) | 0x30;
indexToWrite++;
if(depth > 0) return; // return if we have more levels of recursion to go
else { // finish off the string with the wave extesion
toPlay[indexToWrite] = '.';
toPlay[1+indexToWrite] = 'm';
toPlay[2+indexToWrite] = 'p';
toPlay[3+indexToWrite] = '3';
toPlay[4+indexToWrite] = '\0'; // terminator
indexToWrite = 0; // reset pointer for next time we enter
}
}
void loop() {
makeName(randNumber,0); // generate file name in global array
musicPlayer.startPlayingFile(toPlay);
}