//the code that plays each of the three songs one after the other
/*
THISE CODE DOESNT WORK JUST HERE TO KNOW WHAT I HAD BEFORE
//DF player is connected to RX2 and TX2
#include "DFRobotDFPlayerMini.h"
DFRobotDFPlayerMini player; // Create the Player object
void setup() {
Serial.begin(9600); // Init USB serial port for debugging
Serial2.begin(9600); // Init serial port for DFPlayer Mini
// Start communication with DFPlayer Mini
Serial.println("Connecting to DFplayer");
while (!player.begin(Serial2))
{
Serial.print(".");
delay(1000);
}
Serial.println(" DFplayer connected!");
player.volume(20); // Set volume to maximum (0 to 30).
}
void loop() {
Serial.print("Playing track 1");
player.play(1);
delay(3000);
Serial.print("Playing track 2");
player.play(2);
delay(3000);
Serial.print("Playing track 3");
player.play(3);
delay(3000);
}
*/
//this works for sure
#include "Arduino.h" // Include the core Arduino library
#include "DFRobotDFPlayerMini.h" // Include the DFRobot DFPlayer Mini library
#ifdef ESP32
#define FPSerial Serial1 // For ESP32, use hardware serial port 1
#else
#include <SoftwareSerial.h> // Include SoftwareSerial library for non-ESP32 boards
SoftwareSerial FPSerial(16, 17); // Define SoftwareSerial on pins 16 (RX) and 17 (TX)
#endif
DFRobotDFPlayerMini player; // Create an instance of the DFRobotDFPlayerMini class
void setup() {
#ifdef ESP32
FPSerial.begin(9600, SERIAL_8N1, 16, 17); // Start serial communication for ESP32 with 9600 baud rate, 8 data bits, no parity, and 1 stop bit
#else
FPSerial.begin(9600); // Start serial communication for other boards with 9600 baud rate
#endif
Serial.begin(115200); // Start the Serial monitor communication with 115200 baud rate
Serial.println(F("DFRobot DFPlayer Mini Demo")); // Print a demo start message
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)")); // Print initialization message
if (!player.begin(FPSerial)) { // Initialize the DFPlayer Mini with the defined serial interface
Serial.println(F("Unable to begin:")); // If initialization fails, print an error message
Serial.println(F("1.Please recheck the connection!")); // Suggest rechecking the connection
Serial.println(F("2.Please insert the SD card!")); // Suggest checking for an inserted SD card
while(true); // Stay in an infinite loop if initialization fails
}
Serial.println(F("DFPlayer Mini online.")); // Print a success message if initialization succeeds
player.volume(30); // Set the DFPlayer Mini volume to 30 (max is 30)
player.play(1); // Start playing the first track on the SD card
}
void loop() {
static unsigned long timer = millis(); // Initialize a timer variable to track time elapsed
if (millis() - timer > 9000) { // Check if 9 seconds have passed
timer = millis(); // Reset the timer
player.next(); // Play the next MP3 track
}
if (player.available()) { // Check if the DFPlayer Mini has any new data available
uint8_t type = player.readType(); // Read the type of the message
int value = player.read(); // Read the message value
if (type == DFPlayerPlayFinished) { // Check if the message type indicates the end of a track
Serial.print(F("Finished playing track ")); // Print a message to the Serial monitor
Serial.println(value); // Print the track number that just finished playing
}
}
}
/*
//This works as well
//this works
#include "Arduino.h" // Include the core Arduino library
#include "DFRobotDFPlayerMini.h" // Include the DFRobot DFPlayer Mini library
#ifdef ESP32
#define FPSerial Serial1 // For ESP32, use hardware serial port 1
#else
#include <SoftwareSerial.h> // Include SoftwareSerial library for non-ESP32 boards
SoftwareSerial FPSerial(16, 17); // Define SoftwareSerial on pins 16 (RX) and 17 (TX)
#endif
DFRobotDFPlayerMini player; // Create an instance of the DFRobotDFPlayerMini class
void setup() {
#ifdef ESP32
FPSerial.begin(9600, SERIAL_8N1, 16, 17); // Start serial communication for ESP32 with 9600 baud rate, 8 data bits, no parity, and 1 stop bit
#else
FPSerial.begin(9600); // Start serial communication for other boards with 9600 baud rate
#endif
Serial.begin(115200); // Start the Serial monitor communication with 115200 baud rate
Serial.println(F("DFRobot DFPlayer Mini Demo")); // Print a demo start message
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)")); // Print initialization message
if (!player.begin(FPSerial)) { // Initialize the DFPlayer Mini with the defined serial interface
Serial.println(F("Unable to begin:")); // If initialization fails, print an error message
Serial.println(F("1.Please recheck the connection!")); // Suggest rechecking the connection
Serial.println(F("2.Please insert the SD card!")); // Suggest checking for an inserted SD card
while(true); // Stay in an infinite loop if initialization fails
}
Serial.println(F("DFPlayer Mini online.")); // Print a success message if initialization succeeds
player.volume(30); // Set the DFPlayer Mini volume to 30 (max is 30)
}
void loop() {
Serial.println("Going to play track one");
player.play(1); // Start playing the first track on the SD card
Serial.println("Just played track one");
delay(9000);//after 9 second cut off the current track and start the second one
Serial.println("Going to play track two");
player.play(2); // Start playing the first track on the SD card
Serial.println("Just played track two");
delay(9000);
Serial.println("Going to play track three");
player.play(3); // Start playing the first track on the SD card
Serial.println("Just played track three");
delay(9000);
}
*/