/**
* NOTES: multiple files works on the component that has MP3-TF-16P V3.0 printed on it,
* but DFPlayer Mini only plays a single file...
* To use the DF Mini with a Circuit Playground, we
* cannot use SoftwareSerial library. Instead, we use
* the built-in TX and RX pins that support TTL serial.
* To hook this up, view the left set (hold the module so that the
* label letters are facing correctly) of pins as numbered
* 0 to 7, with 7 closest to where the MicroSD is inserted.
* - pin 0 to 3.3V
* - pin 1 to TX
* - pin 2 to RX
* - pin 3 to nothing
* - pin 4 to nothing
* - pin 5 to red of audio cable
* - pin 6 to to GND
* - pin 7 to black of audio cable
**/
#include <Adafruit_CircuitPlayground.h>
#include "DFRobotDFPlayerMini.h"
// Must connect to dedicated TX and RX (labeled on board)
#define softwareSerial Serial1
// Create the Player object
DFRobotDFPlayerMini player;
bool connected;
int value;
int mp3Num = 1;
int NUM_MP3S = 3; // however many mp3s you have
void setup() {
CircuitPlayground.begin();
// Init USB serial port for debugging
Serial.begin(9600);
// Init serial port for DFPlayer Mini
softwareSerial.begin(9600);
Serial.println( "hello!" );
connectPlayer();
if ( connected )
{
// Play the first MP3 file on the SD card
player.play(1);
delay(3000);
player.play(2);
delay(3000);
Serial.println("Finished playing");
}
}
void connectPlayer() {
// Start communication with DFPlayer Mini
if (player.begin(softwareSerial)) {
Serial.println("OK");
connected = true;
// Set volume to maximum (0 to 30).
player.volume(20);
} else {
Serial.println("Connecting to DFPlayer Mini failed!");
connected = false;
}
}
void loop() {
value = CircuitPlayground.lightSensor();
Serial.print("Light Sensor: ");
Serial.println(value);
if ( value < 5 )
{
if ( !connected )
connectPlayer();
CircuitPlayground.setPixelColor(0, 0, 255, 255);
player.play(mp3Num);
mp3Num = mp3Num % NUM_MP3S + 1; // go to the next mp3; start numbering at 1
delay( 3000 ); // delay to cover length of sound
CircuitPlayground.setPixelColor(0, 0, 0, 0);
}
delay(1000);
}