Skip to content

Simplified version of code for ESP32 #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions examples/Play_particular_MP3_ESP32/Play_particular_MP3_ESP32.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "Arduino.h"
#include "DFRobotDFPlayerMini.h"

// Define the serial port for communication with the DFPlayer Mini
#define FPSerial Serial2

// Create an instance of the DFPlayer Mini
DFRobotDFPlayerMini myDFPlayer;

// Function to print detailed messages from the DFPlayer Mini
void printDetail(uint8_t type, int value) {
// ... (same implementation as before)
}

// Function to play a specific sound file with a given duration
void playSound(int soundNumber, int duration) {
myDFPlayer.play(soundNumber);
delay(duration * 1000); // Convert duration from seconds to milliseconds
}

void setup() {
FPSerial.begin(9600);
Serial.begin(115200);

Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));

if (!myDFPlayer.begin(FPSerial)) {
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while (true) {
delay(0); // Code to compatible with ESP8266 watch dog.
}
}
Serial.println(F("DFPlayer Mini online."));

myDFPlayer.volume(30); // Set volume value. From 0 to 30
}

void loop() {
// Example usage: Play sound file 1 for 5 seconds
playSound(1, 5);
/*
Important: MP3 File Organization
Create a Folder: On your TF card (microSD card), create a folder named mp3 in the root directory.
Organize MP3 Files: Place your MP3 files inside this mp3 folder. Name the files in the format 0001.mp3, 0002.mp3, 0003.mp3, and so on.
/mp3
/0001.mp3
/0002.mp3
/0003.mp3
...
*/
// Add more code here to play other sound files or implement other functionality
}