adds implementation of dfplayer mini
This commit is contained in:
parent
e3b36dd988
commit
c4190e3dfc
2 changed files with 87 additions and 0 deletions
BIN
libraries/DFRobotDFPlayerMini-1.0.5.zip
Normal file
BIN
libraries/DFRobotDFPlayerMini-1.0.5.zip
Normal file
Binary file not shown.
|
@ -2,6 +2,8 @@
|
|||
#include <Wire.h>
|
||||
#include <SPI.h>
|
||||
#include <Adafruit_PN532.h>
|
||||
#include <SoftwareSerial.h>
|
||||
#include <DFRobotDFPlayerMini.h>
|
||||
|
||||
#include "station.h"
|
||||
#include "statemachine.h"
|
||||
|
@ -18,6 +20,9 @@ Adafruit_PN532 nfc(PN532_CS);
|
|||
const int rs = 9, en = 8, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
|
||||
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
|
||||
|
||||
SoftwareSerial softSerial(6, 7); // RX, TX
|
||||
DFRobotDFPlayerMini myDFPlayer;
|
||||
|
||||
Station stations[4] = { Station(1680767519, "Yellow"), Station(3346823711, "Green"), Station(3569318175, "Pink"), Station(2174777887, "Blue") };
|
||||
Station* currentStation;
|
||||
|
||||
|
@ -34,6 +39,23 @@ void setup(void) {
|
|||
|
||||
lcd.begin(16, 2);
|
||||
stationDetectionTimer.start();
|
||||
|
||||
softSerial.begin(9600);
|
||||
|
||||
lcd.print("Initializing MP3");
|
||||
lcd.clear();
|
||||
if (!myDFPlayer.begin(softSerial, true, true)) {
|
||||
lcd.print("Failed to init");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("DFPlayer!");
|
||||
while (true) {
|
||||
delay(100);
|
||||
printMp3Detail(myDFPlayer.readType(), myDFPlayer.read());
|
||||
}
|
||||
}
|
||||
|
||||
myDFPlayer.volume(5);
|
||||
myDFPlayer.play(1);
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
|
@ -119,3 +141,68 @@ Station* detectStation() {
|
|||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
void printMp3Detail(uint8_t type, int value) {
|
||||
lcd.clear();
|
||||
switch (type) {
|
||||
case TimeOut:
|
||||
lcd.print("Time Out!");
|
||||
break;
|
||||
case WrongStack:
|
||||
lcd.print("Stack Wrong!");
|
||||
break;
|
||||
case DFPlayerCardInserted:
|
||||
lcd.print("Card Inserted!");
|
||||
break;
|
||||
case DFPlayerCardRemoved:
|
||||
lcd.print("Card Removed!");
|
||||
break;
|
||||
case DFPlayerCardOnline:
|
||||
lcd.print("Card Online!");
|
||||
break;
|
||||
case DFPlayerUSBInserted:
|
||||
lcd.print("USB Inserted!");
|
||||
break;
|
||||
case DFPlayerUSBRemoved:
|
||||
lcd.print("USB Removed!");
|
||||
break;
|
||||
case DFPlayerPlayFinished:
|
||||
lcd.print("Num:");
|
||||
lcd.print(value);
|
||||
lcd.print(" Finished!");
|
||||
break;
|
||||
case DFPlayerError:
|
||||
lcd.print("DFPlayerError:");
|
||||
switch (value) {
|
||||
case Busy:
|
||||
lcd.print("Card not found");
|
||||
break;
|
||||
case Sleeping:
|
||||
lcd.print("Sleeping");
|
||||
break;
|
||||
case SerialWrongStack:
|
||||
lcd.print("Wrong Stack");
|
||||
break;
|
||||
case CheckSumNotMatch:
|
||||
lcd.print("Checksum Error");
|
||||
break;
|
||||
case FileIndexOut:
|
||||
lcd.print("File Index OOB");
|
||||
break;
|
||||
case FileMismatch:
|
||||
lcd.print("File Mismatch");
|
||||
break;
|
||||
case Advertise:
|
||||
lcd.print("In Advertise");
|
||||
break;
|
||||
default:
|
||||
lcd.print("Unknown Error");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lcd.print("Unknown Type");
|
||||
break;
|
||||
}
|
||||
delay(2000); // Display the message for 2 seconds
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue