Advertisement
microrobotics

DF Robot MP3 Pro Player - 128MB Onboard

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