kartonman

code to start songs as soon as player starts up

Sep 28th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. code to start songs as soon as player starts up
  2.  
  3. #include "SoftwareSerial.h"
  4. #include "DFRobotDFPlayerMini.h"
  5.  
  6. // Use pins 2 and 3 to communicate with DFPlayer Mini
  7. static const uint8_t PIN_MP3_TX = 2; // Connects to module's RX
  8. static const uint8_t PIN_MP3_RX = 3; // Connects to module's TX
  9. SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);
  10.  
  11. // Create the Player object
  12. DFRobotDFPlayerMini player;
  13.  
  14. void setup() {
  15. // Init USB serial port for debugging
  16. Serial.begin(9600);
  17. // Init serial port for DFPlayer Mini
  18. softwareSerial.begin(9600);
  19.  
  20. // Start communication with DFPlayer Mini
  21. if (player.begin(softwareSerial)) {
  22. Serial.println("OK");
  23.  
  24. // Set volume to maximum (0 to 30).
  25. player.volume(30);
  26. // Play the "0001.mp3" in the "mp3" folder on the SD card
  27. player.playMp3Folder(1);
  28.  
  29. } else {
  30. Serial.println("Connecting to DFPlayer Mini failed!");
  31. }
  32. }
  33.  
  34. void loop() {
Advertisement
Add Comment
Please, Sign In to add comment