DFPlayer Pro & Uno

Hi! I am trying to play a random MP3 track from a DFPlayer Pro. All I can do is start it playingand it will play every track consecutively. I cannot pick a single track to play, or play a random track.

void loop() {

int sensorValue = digitalRead(pirSensor);//reads the PIR sensor value
if (sensorValue == 1 ) { //If the PIR sensor is triggered it will do the 2 functions below

playtrack(); //Plays audio selection if it hasn't already been triggered within the time limit selected

selectColor();//Chooses a random color for the eye
delay (timer); // The amount of time the eye color stays on
colorWipe(strip.Color(0, 0, 0), 300); // Resets all LEDs to off

}

}

// This function selects a random audio track from the SD card
void playtrack(){
Serial.print("The number of files available to play:");
//The number of files available to play
Serial.println(DF1201S.getTotalFile());

Serial.print("numsongs :");
//Get file number
Serial.println(numSongs);

//unsigned long currentMillis = millis();
  // if(currentMillis - lastMillis > eventInterval){
     track = random(1,numSongs);
               Serial.print("chosen :");

//Get file number

Serial.println(track);
DF1201S.playFileNum(random(1,numSongs));
Serial.print("File number:");

//Get file number
Serial.println(DF1201S.getCurFileNumber());
//lastMillis = currentMillis;

}

Serial.println(DF1201S.getTotalFile()); returns 0!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.