#include <SoftwareSerial.h>
//#include "DFRobotDFPlayerMini.h"
#define RX_PIN 2 // Define the RX pin for software serial
#define TX_PIN 3 // Define the TX pin for software serial
#define Light4 4
#define Light5 5
#define toggle A2
SoftwareSerial mySerial(RX_PIN, TX_PIN); // Create a software serial object
//DFRobotDFPlayerMini player; // Create a DFPlayer Mini object
int val; // Variable to store the state of toggle switch
int playDelayOn = 3000; // Delay for playing
int playDelayOff = 3000; // Delay for stopping
//----------------------------------------------------
void setup() {
pinMode(Light4, OUTPUT);
pinMode(Light5, OUTPUT);
pinMode(toggle, INPUT);
Serial.begin(9600); // Initialize serial communication for debugging
mySerial.begin(9600); // Initialize software serial communication with DFPlayer Mini
/* if (!player.begin(mySerial)) { // Use software serial to communicate with DFPlayer Mini
while(true); // If DFPlayer Mini is not initialized, halt the program
}
player.volume(30); // Set the volume (0-30)*/
}
//----------------------------------------------
void loop() {
val = digitalRead(toggle);
if (val = HIGH) {
On(); // Call the On function
delay(playDelayOn);
// Play(); // Call the Play function
} else {
Off(); // Call the Off function
}
}
//-------------------------------------------------
void On() {
digitalWrite(Light4, HIGH);
delay(3000);
digitalWrite(Light5, HIGH);
}
//----------------------------------------
/*void Play() {
player.play(1); // Play the first audio file on the SD card
}*/
//---------------------------------------------
void Off() {
// player.stop(); // Stop playing
delay(playDelayOff);
digitalWrite(Light4, LOW);
delay(3000);
digitalWrite(Light5, LOW);
}