I'm making a remote control (via nrf24l01) that among other things, uses a Dfplayer mini to play select tracks as a sort of sound board. However I'd also like to have several tracks play at random from separate folders.
One for the "random tracks"
Another for the sounds played from buttons on the remote.
So far I have it working where the following sketch plays track "0001.mp3" from folder "Mp3" via an analog switch on the remote.
I'd like to Play Tracks 1-10 via the remote buttons in from separate folder, While a random track (sound) plays once Every 3 min.
I'm using the Makuna Library. and I've tried placing tracks 1-10 in a folder "02" and changing:
"mp3.playMp3FolderTrack(1); // sd:/mp3/0001.mp3"
"mp3.playFolderTrack(2, 1);"
following This reference
Nothing I have tried has worked, I've tried moving files renaming them and the folder from 2 to 4 digit numbers and placing a random track play in the loop with a delay but it locks the button out during play.
Can anyone help? or offer better suggestions on how to do what I'm looking to do?
Thank you!
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <SoftwareSerial.h>
#include <DFMiniMp3.h>
#define led 3
RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
int buttonValue;
// implement a notification class,
// its member methods will get called
//
class Mp3Notify
{
public:
static void PrintlnSourceAction(DfMp3_PlaySources source, const char* action)
{
if (source & DfMp3_PlaySources_Sd)
{
Serial.print("SD Card, ");
}
if (source & DfMp3_PlaySources_Usb)
{
Serial.print("USB Disk, ");
}
if (source & DfMp3_PlaySources_Flash)
{
Serial.print("Flash, ");
}
Serial.println(action);
}
static void OnError(uint16_t errorCode)
{
// see DfMp3_Error for code meaning
Serial.println();
Serial.print("Com Error ");
Serial.println(errorCode);
}
static void OnPlayFinished(DfMp3_PlaySources source, uint16_t track)
{
Serial.print("Play finished for #");
Serial.println(track);
}
static void OnPlaySourceOnline(DfMp3_PlaySources source)
{
PrintlnSourceAction(source, "online");
}
static void OnPlaySourceInserted(DfMp3_PlaySources source)
{
PrintlnSourceAction(source, "inserted");
}
static void OnPlaySourceRemoved(DfMp3_PlaySources source)
{
PrintlnSourceAction(source, "removed");
}
};
// instance a DFMiniMp3 object,
// defined with the above notification class and the hardware serial class
//
//DFMiniMp3<HardwareSerial, Mp3Notify> mp3(Serial1);
// Some arduino boards only have one hardware serial port, so a software serial port is needed instead.
// comment out the above definition and uncomment these lines
SoftwareSerial secondarySerial(10, 11); // RX, TX
DFMiniMp3<SoftwareSerial, Mp3Notify> mp3(secondarySerial);
void setup() {
pinMode(3, OUTPUT);
radio.begin();
radio.openWritingPipe(addresses[1]); // 00002
radio.openReadingPipe(1, addresses[0]); // 00001
radio.setPALevel(RF24_PA_MIN);
Serial.begin(115200);
Serial.println("initializing...");
mp3.begin();
uint16_t volume = mp3.getVolume();
Serial.print("volume ");
Serial.println(volume);
mp3.setVolume(24);
uint16_t count = mp3.getTotalTrackCount(DfMp3_PlaySource_Sd);
Serial.print("files ");
Serial.println(count);
Serial.println("starting...");
}
void waitMilliseconds(uint16_t msWait)
{
uint32_t start = millis();
while ((millis() - start) < msWait)
{
// calling mp3.loop() periodically allows for notifications
// to be handled without interrupts
mp3.loop();
delay(1);
}
}
void loop() {
delay(5);
radio.startListening();
buttonValue = analogRead(A2);
if ( radio.available()) {
while (radio.available()) {
radio.read(&buttonValue, sizeof(buttonValue));
}}
if (buttonValue>= 1013 && buttonValue<= 1015) {
digitalWrite(led, HIGH);
Serial.println("track 1");
mp3.playMp3FolderTrack(1); // sd:/mp3/0001.mp3
}
else {
digitalWrite(led, LOW);
}
}``