Hi Everyone,
I am building a project that is a speaker module. The Speaker module sits in standby waiting for a signal from the remote control to make an announcement.
It has a solar panel to keep the battery charged but the Audio Amplifier used can drain the battery over time on cloudy days.
I want to use a relay to switch the Amplifier power on only when its needed. It will be switched on when the module receives a signal to announce and then leave it on for 5min.
If it doesn't receive a signal within that 5mins then it will turn off the Amplifier power again and wait for the next signal to arrive.
If it continues to receive a signal within that 5mins then the 5min timer will keep resetting until it no longer receives a signal and then turns off after 5mins.
I have a loop running that is waiting for a signal to arrive but I cant think of a way to time the amplifier power relay so it stays on for 5mins without this timer stopping the loop function from running.
I am sure there is a way but my programming skills are not quite good enough to make it work.
I know there is a millis routine and Interrupts but not sure the best way to do this.
Here is the loop function below. Any suggestions would be much appreciated.
void loop() {
//Receive Signal
//check if something was received (could be an interrupt from the radio)
if (radio.receiveDone()) //if radio has received a signal check what it is
{
//print message received to serial
Serial.print('['); Serial.print(radio.SENDERID); Serial.print("] ");
Serial.print((char*)radio.DATA);
Serial.print(" [RX_RSSI:"); Serial.print(radio.RSSI); Serial.print("]");
Serial.println();
// if (radio.DATALEN == 1);
if (radio.DATALEN == 1 && radio.DATA[0] == 'H')
{
if (LEDSTATE == LOW) //Turn LED on/off on the receiver board
{
LEDSTATE = HIGH;
digitalWrite(Announce, HIGH);
}
else LEDSTATE = LOW;
digitalWrite(Announce, LOW);
digitalWrite(LED, LEDSTATE);
digitalWrite(RX_TOGGLE_PIN, LEDSTATE);
}
}
radio.receiveDone(); //put radio in RX mode
Serial.flush(); //make sure all serial data is clocked out before sleeping the MCU
}