changes used library for dfplayer
This commit is contained in:
parent
43d31651cd
commit
6997f3c98f
5 changed files with 24 additions and 86 deletions
|
@ -16,3 +16,4 @@ lib_deps =
|
||||||
adafruit/Adafruit BusIO@^1.16.1
|
adafruit/Adafruit BusIO@^1.16.1
|
||||||
dfrobot/DFRobotDFPlayerMini@^1.0.6
|
dfrobot/DFRobotDFPlayerMini@^1.0.6
|
||||||
fmalpartida/LiquidCrystal@^1.5.0
|
fmalpartida/LiquidCrystal@^1.5.0
|
||||||
|
powerbroker2/DFPlayerMini_Fast@^1.2.4
|
||||||
|
|
|
@ -1,73 +1,3 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <DFRobotDFPlayerMini.h>
|
|
||||||
#include <LiquidCrystal.h>
|
#include <LiquidCrystal.h>
|
||||||
|
|
||||||
void printMp3Detail(LiquidCrystal* lcd, 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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,22 @@
|
||||||
#include "Context.h"
|
#include "Context.h"
|
||||||
|
|
||||||
Context::Context(Station* stations, const int stationCount, const unsigned long delta, DFRobotDFPlayerMini* dfPlayer) {
|
Context::Context(Station* stations, const int stationCount, const unsigned long delta, DFPlayerMini_Fast* dfPlayer)
|
||||||
this->stations = stations;
|
{
|
||||||
this->stationCount = stationCount;
|
this->stations = stations;
|
||||||
this->delta = delta;
|
this->stationCount = stationCount;
|
||||||
this->dfPlayer = dfPlayer;
|
this->delta = delta;
|
||||||
|
this->dfPlayer = dfPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Context::getStationIndex(const Station* station) const
|
int Context::getStationIndex(const Station* station) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < stationCount; ++i) {
|
for (int i = 0; i < stationCount; ++i)
|
||||||
if (&stations[i] == station) {
|
{
|
||||||
return i;
|
if (&stations[i] == station)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return -1;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <DFRobotDFPlayerMini.h>
|
#include <DFPlayerMini_Fast.h>
|
||||||
#include "station.h"
|
#include "station.h"
|
||||||
|
|
||||||
class Context {
|
class Context {
|
||||||
public:
|
public:
|
||||||
Context(Station* stations, int stationCount, unsigned long delta, DFRobotDFPlayerMini* dfPlayer);
|
Context(Station* stations, int stationCount, unsigned long delta, DFPlayerMini_Fast* dfPlayer);
|
||||||
|
|
||||||
Station* stations;
|
Station* stations;
|
||||||
int stationCount;
|
int stationCount;
|
||||||
unsigned long delta;
|
unsigned long delta;
|
||||||
DFRobotDFPlayerMini* dfPlayer;
|
DFPlayerMini_Fast* dfPlayer;
|
||||||
|
|
||||||
int getStationIndex(const Station* station) const;
|
int getStationIndex(const Station* station) const;
|
||||||
|
bool isPlaying() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <Adafruit_PN532.h>
|
#include <Adafruit_PN532.h>
|
||||||
#include <SoftwareSerial.h>
|
#include <SoftwareSerial.h>
|
||||||
#include <DFRobotDFPlayerMini.h>
|
#include <DFPlayerMini_Fast.h>
|
||||||
|
|
||||||
#include "station.h"
|
#include "station.h"
|
||||||
#include "statemachine.h"
|
#include "statemachine.h"
|
||||||
|
@ -22,7 +22,7 @@ constexpr int rs = 9, en = 8, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
|
||||||
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
|
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
|
||||||
|
|
||||||
SoftwareSerial softSerial(6, 7); // RX, TX
|
SoftwareSerial softSerial(6, 7); // RX, TX
|
||||||
DFRobotDFPlayerMini dfPlayer;
|
DFPlayerMini_Fast dfPlayer;
|
||||||
|
|
||||||
Station stations[5] = {
|
Station stations[5] = {
|
||||||
Station(1680767519, "Yellow"), Station(3346823711, "Green"), Station(3569318175, "Pink"),
|
Station(1680767519, "Yellow"), Station(3346823711, "Green"), Station(3569318175, "Pink"),
|
||||||
|
@ -176,7 +176,8 @@ void setup(void)
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
delay(100);
|
delay(100);
|
||||||
printMp3Detail(&lcd, dfPlayer.readType(), dfPlayer.read());
|
dfPlayer.printError();
|
||||||
|
// printMp3Detail(&lcd, dfPlayer.readType(), dfPlayer.read());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue