Using PowerBroker's DF Mini Fast Library: GitHub - PowerBroker2/DFPlayerMini_Fast: Fast and easy to understand Arduino library to use the DFPlayer Mini MP3 module from DFRobot.com. This is a huge improvement (both in terms of execution speed and simplicity) to the standard library provided by DFRobot.com.
I would like to use an Arduino UNO, DF Mini Mp3 player, LED, and PIR sensor to make a startle noise prop for the Trick or Treaters. What I would like is to have an ambient soundtrack playing, namely Disney's Haunted Mansion soundtrack playing as they enter the yard. I would like that saved in Folder 0 of the MP3 player.
Once a Trick or Treater sets off the PIR, I would then like to play a random yell or scream from Folder 1. After that short scream, I would like to resume playing the soundtrack in Folder 0 from where it left off when the PIR triggered Folder 1 to go off. What I'm trying to avoid is guests and my own self having to hear "Welcome Foolish Mortals" (the start of the soundtrack) 1000 times Halloween night.
So I see this in this thread where PowerBroker references this function:
randomSeed(analogRead(0));
randNumber = random(10);
But I have been unsuccessful in adapting that in my sketch.
Here it is. This does compile, but does not function. If I call a specific file, it does work. But I'm trying to use this with random in Folder 0, (maybe even in Folder 1) and Pausing the ambient soundtrack in Folder 1 and resuming it after the interruption by the PIR.
/* PIR sensor tester
/*/
#include <SoftwareSerial.h>
#include <DFPlayerMini_Fast.h>
SoftwareSerial mySerial(10, 11); // RX, TX
DFPlayerMini_Fast myMP3;
int ledPin = 7; // choose the pin for the LED
int inputPin = 9; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
Serial.begin(115200);
mySerial.begin(9600);
myMP3.begin(mySerial);
Serial.println("Setting volume to max");
myMP3.volume(10);
delay(20);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
Serial.println("Playing track 5");
myMP3.playFolder(0,1);
delay(5000);
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
myMP3.playFolder(1,1);
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned off
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
myMP3.playFolder(0,1);
}
}
}
I am unsure if I need to time or poll the player (isPlaying) to make this work. Thank you for your help in advance.
