Mp3 player with MD_YX5300 library **UPDATE BELOW**

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 :sweat_smile:

I think the library will have a function to stop playing.

What option? You mean the options to play different folders based on a pin reading high or low. I think no library will have the exact function you want. Libraries contain functions which are more general in their purpose. You must write code to use the library functions in the way you want.

when you tell the module to start playing, it runs by itself until the file you played stops, or

if you tell the module to play a different tune before the first tune finishes, it terminates the first one and starts the next one.

either way, you start it and the Arduino goes back to the main program. the Arduino does other tasks after you start the YX-5300

playStop()

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