CCCPaste

Audio Control rev_03

/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: Audio Control
	- Source Code NOT compiled for: Arduino Uno
	- Source Code created on: 2024-09-20 20:31:05

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* Play Track 1.  play random track between 2 and 5. */
/****** SYSTEM REQUIREMENT 2 *****/
	/* play track for 3 minutes.  Shut down for 2 minutes */
	/* then loop */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 
#include 	//https://github.com/DFRobot/DFRobotDFPlayerMini

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);
void playTracks(void);

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t LED_LED_PIN_D2		= 2;

/***** DEFINITION OF Software Serial *****/
const uint8_t DFPlayer_DFPlayerMini_Serial_PIN_SERIAL_TX_A0		= A0;
const uint8_t DFPlayer_DFPlayerMini_Serial_PIN_SERIAL_RX_A1		= A1;
SoftwareSerial DFPlayer_DFPlayerMini_Serial(DFPlayer_DFPlayerMini_Serial_PIN_SERIAL_RX_A1, DFPlayer_DFPlayerMini_Serial_PIN_SERIAL_TX_A0);

/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool	LED_LED_PIN_D2_rawData		= 0;

/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float	LED_LED_PIN_D2_phyData		= 0.0;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
// Instantiate the DFPlayer object
DFRobotDFPlayerMini myDFPlayer; // Correct initialization of DFPlayer object

void setup(void)
{
	// put your setup code here, to run once:
	pinMode(LED_LED_PIN_D2, OUTPUT);

	// Initialize software serial for DFPlayer
	DFPlayer_DFPlayerMini_Serial.begin(9600);

	// Initialize the DFPlayer
	if (!myDFPlayer.begin(DFPlayer_DFPlayerMini_Serial, true, true)) { // Use serial to communicate with mp3
		Serial.println(F("Unable to begin:"));
		Serial.println(F("1. Please recheck the connection!"));
		Serial.println(F("2. Please insert the SD card!"));
		while(true); // Loop forever if initialization fails
	}
	Serial.println(F("DFPlayer Mini online."));
	myDFPlayer.volume(10); // Set volume value (0~30)
}

void loop(void)
{
	// put your main code here, to run repeatedly:
	playTracks(); // Call the function to play tracks
}

void playTracks()
{
	// Play track 1
	myDFPlayer.play(1); // Play track 1
	delay(180000); // Play for 3 minutes (180000 milliseconds)

	// Play a random track between 2 and 5
	int randomTrack = random(2, 6); // Generate a random number between 2 and 5
	myDFPlayer.play(randomTrack); // Play the random track
	delay(180000); // Play for 3 minutes (180000 milliseconds)

	// Shut down for 2 minutes
	myDFPlayer.stop(); // Stop playing
	delay(120000); // Wait for 2 minutes (120000 milliseconds)

	// Loop back to the beginning of the function to repeat the process
	playTracks(); // Call the function again to loop
}

void updateOutputs()
{
	digitalWrite(LED_LED_PIN_D2, LED_LED_PIN_D2_rawData);
}

/* END CODE */