Dear Community,
I have been wondering how to make mp3-tf-16p soundmodule to play randomly only one song when button is pressed once. I couldn´t find a proper scetch ready.
Has anyone seen a scetch needed? I would appreciate help a lot.
Dear Community,
I have been wondering how to make mp3-tf-16p soundmodule to play randomly only one song when button is pressed once. I couldn´t find a proper scetch ready.
Has anyone seen a scetch needed? I would appreciate help a lot.
Using a library such as this one combined with the built-in functions randomSeed() and random(), you can figure out a way to play a random song.
Here's an example (assuming you have 10 different tracks on your SD card):
#include <SoftwareSerial.h>
#include <DFPlayerMini_Fast.h>
SoftwareSerial mySerial(10, 11); // RX, TX
DFPlayerMini_Fast myMP3;
int randNumber;
void setup()
{
Serial.begin(115200);
mySerial.begin(9600);
myMP3.begin(mySerial);
randomSeed(analogRead(0));
randNumber = random(10);
Serial.println("Setting volume to max");
myMP3.volume(30);
delay(20);
Serial.println("Looping random track");
myMP3.loop(randNumber);
}
void loop()
{
//do nothing
}
Btw, you can install the linked library in the Arduino IDE Library Manager - just search "DFPlayerMini_Fast"
PowerBroker, with the changes to the library, is this still a correct answer? I am attempting to duplicate this and keep getting the same MP3 files playing everytime. I'm sure it changed to some variation of randomAll, but unsure how to do it with differing folders like the OP. Thanks for your help in advance.
It depends on what you want your code to do. What do you want your code to do?
PowerBroker, I made a seperate thread for that here, I didn't want to hijack this topic. Thanks as always!