Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
|
#include <DFPlayerMini.h>
Public Types | |
enum | Cmd { Undefined = 0x00, Next = 0x01, Prev = 0x02, PlayPhysical = 0x03, SetVolume = 0x06, SetEqalizer = 0x07, SetDevice = 0x09, Sleep = 0x0A, Reset = 0x0C, Play = 0x0D, Pause = 0x0E, PlayTf = 0x12, Stop = 0x16, SingleLoop = 0x19, GetStatus = 0x42, GetVolume = 0x43, GetUSum = 0x47, GetTfSum = 0x48, GetFlashSum = 0x49, GetUCurrent = 0x4B, GetTfCurrent = 0x4C, GetFlashCurrent = 0x4D } |
Public Member Functions | |
DFPlayerMini (Stream &serial, const uint8_t busyPin=0) | |
void | begin (bool bootWait=true) |
void | sendCmd (Cmd cmd, uint16_t arg=0) |
DFPResponse | query (Cmd cmd, uint8_t tries=3) |
bool | busy () |
bool | check () |
Easy-to-use controller class for DFPlayer Mini devices.
This class implements some of the functionality of the DFPlayer_Mini_MP3 library, to control a DFPlayer Mini device. It includes features which were not yet implemented in the DFPlayer_Mini_MP3 at time of writing, namely a mechanism to receive results of query calls to the device.
The device is expected to be connected using serial and optionally the BUSY line. Serial comms are at 9600 baud. The BUSY line is pulled to ground when the DFPlayerMini device is playing an mp3 file.
See also:
Definition at line 25 of file DFPlayerMini.h.
enum DFPlayerMini::Cmd |
Command codes.
The DFPlayerMini's serial interface uses this set of command codes to instruct the device to perform some action or reply with some information.
Definition at line 44 of file DFPlayerMini.h.
DFPlayerMini::DFPlayerMini | ( | Stream & | serial, |
const uint8_t | busyPin = 0 |
||
) |
Constructor.
serial | a software serial object set at 9600 baud connected to the DFPlayerMini device |
busyPin | the pin on the arduino connected to the BUSY pin of the DFPlayerMini. See the busy() documentation for more details. |
Definition at line 6 of file DFPlayerMini.cpp.
void DFPlayerMini::begin | ( | bool | bootWait = true | ) |
Initialization.
Sets up pin modes and resets state - typically called from begin().
bootWait | if true, delay for about 600ms to allow the DFPlayer to boot. Failure to wait can cause the DFPlayer to miss initial commands like volume setting. |
Definition at line 13 of file DFPlayerMini.cpp.
bool DFPlayerMini::busy | ( | ) |
Find out if a sound is playing.
If the BUSY pin has been connected to the arduino and properly set with the busyPin parameter to the DFPlayerMini constructor, the value will be determined by analysing this pin state.
If the busy pin was not passed when the DFPlayerMini was constructed, a GetStatus query will be sent to the player and the result analysed to determine the result. Note that the query method will cause jitter in the audio playback, and takes longer to execute, so the BUSY pin method is recommended if there is a digital input available.
Definition at line 164 of file DFPlayerMini.cpp.
bool DFPlayerMini::check | ( | ) |
Find out if we can communicate with the device.
Definition at line 215 of file DFPlayerMini.cpp.
DFPResponse DFPlayerMini::query | ( | DFPlayerMini::Cmd | cmd, |
uint8_t | tries = 3 |
||
) |
Send a command and wait for a response.
cmd | The command to send. |
tries | how many attempts will be made to get a valid result. |
Definition at line 56 of file DFPlayerMini.cpp.
void DFPlayerMini::sendCmd | ( | DFPlayerMini::Cmd | cmd, |
uint16_t | arg = 0 |
||
) |
Send a command no response is expected.
cmd | The command to send |
arg | The argument to the command, if one is expected |
Definition at line 32 of file DFPlayerMini.cpp.