Skip to content

Instantly share code, notes, and snippets.

@madbunnykim madbunnykim/Baenana
Last active Feb 4, 2019

Embed
What would you like to do?
Baenana
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
const int PEEL1 = 2;
const int PEEL2 = 3;
const int PEEL3 = 4;
const int PEEL4 = 5;
int counter = 0;
boolean isPlaying = false;
boolean played1 = false;
boolean played2 = false;
boolean played3 = false;
boolean played4 = false;
void setup() {
mySoftwareSerial.begin(9600);
Serial.begin(115200);
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."));
pinMode(PEEL1, INPUT);
pinMode(PEEL2, INPUT);
pinMode(PEEL3, INPUT);
pinMode(PEEL4, INPUT);
}
void loop() {
if (digitalRead(PEEL1) == LOW && played1 == false) {
// Serial.println("I am on");
myDFPlayer.volume(30);
myDFPlayer.play(counter);
delay(1000);
counter = counter + 1;
Serial.println(counter);
if (counter == 41) {
counter = 0;
}
played1 = true;
}
if (digitalRead(PEEL1) == HIGH) {
played1 = false;
}
if (digitalRead(PEEL2) == LOW && played2 == false) {
// Serial.println("I am on");
myDFPlayer.volume(30);
myDFPlayer.play(counter);
delay(1000);
counter = counter + 1;
Serial.println(counter);
if (counter == 41) {
counter = 0;
}
played2 = true;
}
if (digitalRead(PEEL2) == HIGH) {
played2 = false;
}
if (digitalRead(PEEL3) == LOW && played3 == false) {
// Serial.println("I am on");
myDFPlayer.volume(30);
myDFPlayer.play(counter);
delay(1000);
counter = counter + 1;
Serial.println(counter);
if (counter == 41) {
counter = 0;
}
played3 = true;
}
if (digitalRead(PEEL3) == HIGH) {
played3 = false;
}
if (digitalRead(PEEL4) == LOW && played4 == false) {
// Serial.println("I am on");
myDFPlayer.volume(30);
myDFPlayer.play(counter);
delay(1000);
counter = counter + 1;
Serial.println(counter);
if (counter == 41) {
counter = 0;
}
played4 = true;
}
if (digitalRead(PEEL4) == HIGH) {
played4 = false;
}
// if (myDFPlayer.available()) {
// printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
// }
}
//void printDetail(uint8_t type, int value) {
// switch (type) {
// case TimeOut:
// Serial.println(F("Time Out!"));
// break;
// case WrongStack:
// Serial.println(F("Stack Wrong!"));
// break;
// case DFPlayerCardInserted:
// Serial.println(F("Card Inserted!"));
// break;
// case DFPlayerCardRemoved:
// Serial.println(F("Card Removed!"));
// break;
// case DFPlayerCardOnline:
// Serial.println(F("Card Online!"));
// break;
// case DFPlayerPlayFinished:
// Serial.print(F("Number:"));
// Serial.print(value);
// Serial.println(F(" Play Finished!"));
// break;
// case DFPlayerError:
// Serial.print(F("DFPlayerError:"));
// switch (value) {
// case Busy:
// Serial.println(F("Card not found"));
// break;
// case Sleeping:
// Serial.println(F("Sleeping"));
// break;
// case SerialWrongStack:
// Serial.println(F("Get Wrong Stack"));
// break;
// case CheckSumNotMatch:
// Serial.println(F("Check Sum Not Match"));
// break;
// case FileIndexOut:
// Serial.println(F("File Index Out of Bound"));
// break;
// case FileMismatch:
// Serial.println(F("Cannot Find File"));
// break;
// case Advertise:
// Serial.println(F("In Advertise"));
// break;
// default:
// break;
// }
// break;
// default:
// break;
// }
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.