Advertisement
Guest User

boite a rythme papa maker

a guest
Mar 22nd, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /***************************************************
  2. DFPlayer - A Mini MP3 Player For Arduino
  3.  <https://www.dfrobot.com/product-1121.html>
  4.  
  5.  ***************************************************
  6.  This example shows the basic function of library for DFPlayer.
  7.  
  8.  Created 2016-12-07
  9.  By [Angelo qiao](Angelo.qiao@dfrobot.com)
  10.  
  11.  GNU Lesser General Public License.
  12.  See <http://www.gnu.org/licenses/> for details.
  13.  All above must be included in any redistribution
  14.  ****************************************************/
  15.  
  16. /***********Notice and Trouble shooting***************
  17.  1.Connection and Diagram can be found here
  18.  <https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299#Connection_Diagram>
  19.  2.This code is tested on Arduino Uno, Leonardo, Mega boards.
  20.  ****************************************************/
  21.  
  22. #include "Arduino.h"
  23. #include "SoftwareSerial.h"
  24. #include "DFRobotDFPlayerMini.h"
  25.  
  26. SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
  27. DFRobotDFPlayerMini myDFPlayer;
  28. void printDetail(uint8_t type, int value);
  29.  
  30. int buttonState;
  31. int lastButtonState = HIGH;
  32. unsigned long lastDebounceTime = 0;
  33.  
  34. int buttonState2;
  35. int lastButtonState2 = HIGH;
  36. unsigned long lastDebounceTime2 = 0;
  37.  
  38.  
  39.  
  40.  
  41. void setup()
  42. {
  43.   mySoftwareSerial.begin(9600);
  44.   Serial.begin(115200);
  45.  
  46.   Serial.println();
  47.   Serial.println(F("DFRobot DFPlayer Mini Demo"));
  48.   Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
  49.  
  50.   if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
  51.     Serial.println(F("Unable to begin:"));
  52.     Serial.println(F("1.Please recheck the connection!"));
  53.     Serial.println(F("2.Please insert the SD card!"));
  54.     while(true){
  55.       delay(0); // Code to compatible with ESP8266 watch dog.
  56.     }
  57.   }
  58.   Serial.println(F("DFPlayer Mini online."));
  59.  
  60.   pinMode (5, INPUT_PULLUP);
  61.   pinMode (4, INPUT_PULLUP);
  62.   pinMode (3, INPUT_PULLUP);
  63.   pinMode (2, INPUT_PULLUP);
  64.   myDFPlayer.volume(10);  //Set volume value. From 0 to 30
  65.  
  66. }
  67.  
  68. void loop()
  69. {
  70.  int reading = digitalRead (5);
  71.  if (reading != lastButtonState){
  72.   lastDebounceTime = millis () ;
  73.   }
  74.   if ((millis() - lastDebounceTime) > 50){
  75.     if (reading !=lastButtonState){
  76.       buttonState = reading;
  77.       if (buttonState ==LOW) {
  78.         myDFPlayer.play(1);
  79.       }
  80.     }
  81.   }
  82.   lastButtonState = reading;
  83.  
  84.    int reading2 = digitalRead (4);
  85.  if (reading2 != lastButtonState2){
  86.   lastDebounceTime2 = millis () ;
  87.   }
  88.   if ((millis() - lastDebounceTime2) > 50){
  89.     if (reading2 !=lastButtonState2){
  90.       buttonState2 = reading2;
  91.       if (buttonState2 ==LOW) {
  92.         myDFPlayer.play(2);
  93.       }
  94.     }
  95.   }
  96.   lastButtonState2 = reading2;
  97.  
  98. }
  99.  
  100. void printDetail(uint8_t type, int value){
  101.   switch (type) {
  102.     case TimeOut:
  103.       Serial.println(F("Time Out!"));
  104.       break;
  105.     case WrongStack:
  106.       Serial.println(F("Stack Wrong!"));
  107.       break;
  108.     case DFPlayerCardInserted:
  109.       Serial.println(F("Card Inserted!"));
  110.       break;
  111.     case DFPlayerCardRemoved:
  112.       Serial.println(F("Card Removed!"));
  113.       break;
  114.     case DFPlayerCardOnline:
  115.       Serial.println(F("Card Online!"));
  116.       break;
  117.     case DFPlayerUSBInserted:
  118.       Serial.println("USB Inserted!");
  119.       break;
  120.     case DFPlayerUSBRemoved:
  121.       Serial.println("USB Removed!");
  122.       break;
  123.     case DFPlayerPlayFinished:
  124.       Serial.print(F("Number:"));
  125.       Serial.print(value);
  126.       Serial.println(F(" Play Finished!"));
  127.       break;
  128.     case DFPlayerError:
  129.       Serial.print(F("DFPlayerError:"));
  130.       switch (value) {
  131.         case Busy:
  132.           Serial.println(F("Card not found"));
  133.           break;
  134.         case Sleeping:
  135.           Serial.println(F("Sleeping"));
  136.           break;
  137.         case SerialWrongStack:
  138.           Serial.println(F("Get Wrong Stack"));
  139.           break;
  140.         case CheckSumNotMatch:
  141.           Serial.println(F("Check Sum Not Match"));
  142.           break;
  143.         case FileIndexOut:
  144.           Serial.println(F("File Index Out of Bound"));
  145.           break;
  146.         case FileMismatch:
  147.           Serial.println(F("Cannot Find File"));
  148.           break;
  149.         case Advertise:
  150.           Serial.println(F("In Advertise"));
  151.           break;
  152.         default:
  153.           break;
  154.       }
  155.       break;
  156.     default:
  157.       break;
  158.   }
  159.  
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement