Advertisement
kartonman

DFPLAYER PLAY EXAMPLE

Sep 23rd, 2021
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. /*!
  2. *@file play.ino
  3. *@brief Music Playing Example Program
  4.  
  5. */
  6.  
  7. #include <DFRobot_PLAY.h>
  8. #include <SoftwareSerial.h>
  9.  
  10. SoftwareSerial DF1201SSerial(2, 3); //RX TX
  11. DFRobot_PLAY DF1201S;
  12.  
  13. //*************************************************
  14. void setup(void){
  15. Serial.begin(115200);
  16. DF1201SSerial.begin(115200);
  17. while(!DF1201S.begin(DF1201SSerial)){
  18. Serial.println("Init failed, please check the wire connection!");
  19. delay(1000);
  20. }
  21. /*Set volume to 20*/
  22. DF1201S.setVol(/*VOL = */20);
  23. Serial.print("VOL:");
  24. /*Get volume*/
  25. Serial.println(DF1201S.getVol());
  26. /*Enter music mode*/
  27. DF1201S.switchFunction(DF1201S.MUSIC);
  28. /*Wait for the end of the prompt tone */
  29. delay(2000);
  30. /*Set playback mode to "repeat all"*/
  31. DF1201S.setPlayMode(DF1201S.ALLCYCLE);
  32. Serial.print("PlayMode:");
  33. /*Get playback mode*/
  34. Serial.println(DF1201S.getPlayMode());
  35.  
  36. //Set baud rate to 115200(Need to power off and restart, power-down save)
  37. //DF1201S.setBaudRate(115200);
  38. //Turn on indicator LED (Power-down save)
  39. //DF1201S.setLED(true);
  40. //Turn on the prompt tone (Power-down save)
  41. //DF1201S.setPrompt(true);
  42. //Enable amplifier chip
  43. //DF1201S.enableAMP();
  44. //Disable amplifier chip
  45. //DF1201S.disableAMP();
  46. }
  47. //***********************************************************************
  48. void loop(){
  49. Serial.println("Start playing");
  50. /*Start playing*/
  51. DF1201S.start();
  52. delay(3000);
  53. Serial.println("Pause");
  54. /*Pause*/
  55. DF1201S.pause();
  56. delay(3000);
  57. Serial.println("Next");
  58. /*Play the next song*/
  59. DF1201S.next();
  60. delay(3000);
  61. Serial.println("Previous");
  62. /*Play the previous song*/
  63. DF1201S.last();
  64. delay(3000);
  65. Serial.println("Start playing");
  66. //Fast forward 10S
  67. DF1201S.fastForward(/*FF = */10);
  68. //Fast Rewind 10S
  69. //DF1201S.fastReverse(/*FR = */10);
  70. //Start the song from the 10th second
  71. //DF1201S.setPlayTime(/*Play Time = */10);
  72.  
  73. Serial.print("File number:");
  74. //Get file number
  75. Serial.println(DF1201S.getCurFileNumber());
  76.  
  77. Serial.print("The number of files available to play:");
  78. //The number of files available to play
  79. Serial.println(DF1201S.getTotalFile());
  80.  
  81. Serial.print("The time length the current song has played:");
  82. //Get the time length the current song has played
  83. Serial.println(DF1201S.getCurTime());
  84.  
  85. Serial.print("The total length of the currently-playing song: ");
  86. //Get the total length of the currently-playing song
  87. Serial.println(DF1201S.getTotalTime());
  88. Serial.print("The name of the currently-playing file: ");
  89. //Get the name of the playing file
  90. Serial.println(DF1201S.getFileName());
  91. delay(3000);
  92. //Play the file No.1, the numbers are arranged according to the sequence of the files copied into the U-disk
  93. DF1201S.playFileNum(/*File Number = */1);
  94. //Play the test.mp3 file in test folder
  95. //DF1201S.playSpecFile("/test/test.mp3");
  96.  
  97. while(1);
  98. /*Delete the currently-playing file */
  99. //DF1201S.delCurFile();
  100. }
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement