Easy IoT General

DFplayer and Arduino

userHead Account cancelled 2018-04-21 07:40:42 2974 Views0 Replies
I'm trying to have a file play with the press of a momentary button. (I am using the DFRobotDFPlayerMini library with an Arduino) If I let off the button the file stops playing. If I don't use an arduino, the file will play once via the IO pins but I would like to get this function on the arduino through serial trigger. The code I am using is below.
Code: Select all
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
int buttonInput = 3;
int buttonState = 0;

SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);

void setup()
{
  mySoftwareSerial.begin(9600);
  Serial.begin(115200);
  pinMode(buttonInput, INPUT_PULLUP);
  Serial.println();
  Serial.println(F("DFRobot DFPlayer Mini Demo"));
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
  
  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    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);
  }
  Serial.println(F("DFPlayer Mini online."));
  
  myDFPlayer.volume(20);  //Set volume value. From 0 to 30
  
}

void loop()
{
  buttonState = digitalRead(buttonInput);
    if (buttonState == HIGH) {
   myDFPlayer.play(1);
    }
}