Split code between ulanzi environment and awtrix_upgrade
Added BME280 sensor support for awtrix_upgrade. Removed battery readings for awtrix_upgrade Added DFMiniMp3 lib for replacing the Ulanzi buzzer in the future
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
// this example will play a random track from all on the sd
|
||||
//
|
||||
// it expects the sd card to contain some mp3 files
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
#include <DFMiniMp3.h>
|
||||
|
||||
// implement a notification class,
|
||||
// its member methods will get called
|
||||
//
|
||||
class Mp3Notify
|
||||
{
|
||||
public:
|
||||
static void PrintlnSourceAction(DfMp3_PlaySources source, const char* action)
|
||||
{
|
||||
if (source & DfMp3_PlaySources_Sd)
|
||||
{
|
||||
Serial.print("SD Card, ");
|
||||
}
|
||||
if (source & DfMp3_PlaySources_Usb)
|
||||
{
|
||||
Serial.print("USB Disk, ");
|
||||
}
|
||||
if (source & DfMp3_PlaySources_Flash)
|
||||
{
|
||||
Serial.print("Flash, ");
|
||||
}
|
||||
Serial.println(action);
|
||||
}
|
||||
static void OnError(uint16_t errorCode)
|
||||
{
|
||||
// see DfMp3_Error for code meaning
|
||||
Serial.println();
|
||||
Serial.print("Com Error ");
|
||||
Serial.println(errorCode);
|
||||
}
|
||||
static void OnPlayFinished(DfMp3_PlaySources source, uint16_t track)
|
||||
{
|
||||
Serial.print("Play finished for #");
|
||||
Serial.println(track);
|
||||
}
|
||||
static void OnPlaySourceOnline(DfMp3_PlaySources source)
|
||||
{
|
||||
PrintlnSourceAction(source, "online");
|
||||
}
|
||||
static void OnPlaySourceInserted(DfMp3_PlaySources source)
|
||||
{
|
||||
PrintlnSourceAction(source, "inserted");
|
||||
}
|
||||
static void OnPlaySourceRemoved(DfMp3_PlaySources source)
|
||||
{
|
||||
PrintlnSourceAction(source, "removed");
|
||||
}
|
||||
};
|
||||
|
||||
// instance a DFMiniMp3 object,
|
||||
// defined with the above notification class and the hardware serial class
|
||||
//
|
||||
DFMiniMp3<HardwareSerial, Mp3Notify> mp3(Serial1);
|
||||
|
||||
// Some arduino boards only have one hardware serial port, so a software serial port is needed instead.
|
||||
// comment out the above definition and uncomment these lines
|
||||
//SoftwareSerial secondarySerial(10, 11); // RX, TX
|
||||
//DFMiniMp3<SoftwareSerial, Mp3Notify> mp3(secondarySerial);
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("initializing...");
|
||||
|
||||
mp3.begin();
|
||||
mp3.reset();
|
||||
|
||||
// show some properties and set the volume
|
||||
uint16_t volume = mp3.getVolume();
|
||||
Serial.print("volume ");
|
||||
Serial.println(volume);
|
||||
mp3.setVolume(24);
|
||||
|
||||
uint16_t count = mp3.getTotalTrackCount(DfMp3_PlaySource_Sd);
|
||||
Serial.print("files ");
|
||||
Serial.println(count);
|
||||
|
||||
uint16_t mode = mp3.getPlaybackMode();
|
||||
Serial.print("playback mode ");
|
||||
Serial.println(mode);
|
||||
|
||||
Serial.println("starting...");
|
||||
|
||||
mp3.playRandomTrackFromAll(); // random of all folders on sd
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// calling mp3.loop() periodically allows for notifications
|
||||
// to be handled without interrupts
|
||||
mp3.loop();
|
||||
}
|
||||
Reference in New Issue
Block a user