hello every one
I'm trying to build a project with those parts
arduino uno
mp3 player, YX5300 (rx 13 and tx 12)
ky-003 pin 3
I'm trying to figure how to write a code so when Pin 3 is LOW the player will play the file in folders 1-3 in repeat.
and when HIGH play the file in folder 3 once.
or 1 in repeat and 2 if HIGH
is it even possible to stop the music will playing?
maybe the library MD_YX5300 don't have the option? is there other library that can do it?
*** UPDATE ***
I manage to do it using enum, switch and millis
however I can't make it play the 3 folders in repeat, only one...
this is the code:
#include <SoftwareSerial.h>
#include <MD_YX5300.h>
#define RX_PIN 13
#define TX_PIN 12
const int pin3 = 3;
SoftwareSerial mySerial(RX_PIN, TX_PIN); // RX, TX
MD_YX5300 mp3(mySerial);
enum State {
PLAYING,
STOPPED
};
State currentState = STOPPED;
unsigned long previousMillis = 0;
unsigned long interval = 5000; // 5 seconds
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
pinMode(pin3, INPUT);
mp3.begin();
mp3.volume(15);
}
void loop()
{
switch (currentState) {
case PLAYING:
if (digitalRead(pin3) == HIGH) {
currentState = STOPPED;
mp3.playStop();
mp3.playSpecific(2, 1);
}
break;
case STOPPED:
if (millis() - previousMillis >= interval) {
currentState = PLAYING;
mp3.playSpecific(1, 1);
mp3.repeat(true);
previousMillis = millis();
}
break;
}
// Other code in the main loop
}
I used chat gpt for help