I've done a bit of digging, and found multiple methodologies to delay without delay(), but I cannot for the life of me integrate any of them to this code.
The issue with delay, is I want the 'else if' function to still work as that is an over ride to turn the device off. (actual run time is going to be 45mins, not 5 secs)
The two 'values' correspond to buttons 1 and 2 on an RF TX.
My Code (so far) is;
/*
Modifed simple receiving code created by the awesome people at:
http://code.google.com/p/rc-switch/
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
pinMode(4, OUTPUT); // Location of Mosfet
pinMode(6, OUTPUT); // Operation Indicator LED (optional)
}
void loop() {
if (mySwitch.available()) {
unsigned long value = mySwitch.getReceivedValue();
if (value == 7419184) // This is the value received when button one on TX is pushed
{
Serial.print("Mosfet ON - Value: "); // This and the next three lines are for debug and testing purposes
Serial.print(mySwitch.getReceivedValue() );
Serial.println("");
digitalWrite(4, HIGH); // set the Mosfet On
digitalWrite(6, HIGH); // set the LED on
delay(5000); // wait for 5 seconds
digitalWrite(4, LOW); // set the Mosfet Off
digitalWrite(6, LOW); // set the LED Off
}
else if (value == 7419139) // This is the value received when button two on TX is pushed
{
Serial.print("Mosfet OFF - Value: "); // This and the next two lines are for debug and testing purposes
Serial.print(mySwitch.getReceivedValue() );
Serial.println("");
digitalWrite(4, LOW); // set the Mosfet Off
digitalWrite(6, LOW); // set the LED Off
}
else // If neither of the above two values are received it activates this message.
{
Serial.print("Received Other Value: "); // This and the next two lines are for debug and testing purposes
Serial.print(mySwitch.getReceivedValue() );
Serial.println("");
}
mySwitch.resetAvailable();
}
}
Would appreciate any help on this, it's taken me nearly 6 hours to get this far (tonight anyway...) I'm by no means a professional at this.