I've had a go using the for(int expression as i thought with the delay only being 1ms it would work, but still no joy.
There are a lot of libraries that implement timers, but all of the examples are a repeating scenario, somthing that flashes, where as I need a one shot.
/*
Modifed simple receiving code created by the awesome people at:
http://code.google.com/p/rc-switch/
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
int Mosfet = 3; // Pin that activates your Mosfet
int LED1 = 11; // Pin that activates an LED
int LED2 = 12;
int RunMosfet = 5000; /// Run times can be calculated as ms, or S * 1000 where S is your seconds, M * 60 * 1000 where M is your minutes and H * 60 * 60 * 1000 where H is hours ///
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
pinMode(Mosfet, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
/// Run times can be calculated as ms, or S * 1000 where S is your seconds, M * 60 * 1000 where M is your minutes and H * 60 * 60 * 1000 where H is hours ///
}
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(LED1, HIGH);
for (int x=0; x < 150; x++) { // Wait for 1 second
delay(1); }
digitalWrite(LED1, LOW);
digitalWrite(Mosfet, HIGH);
for (int x=0; x < RunMosfet; x++) { // Wait for 1 second
delay(1); }
digitalWrite(Mosfet, LOW);
digitalWrite(LED1, HIGH);
for (int x=0; x < 150; x++) { // Wait for 1 second
delay(1); }
digitalWrite(LED1, LOW);
}
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(Mosfet, LOW); // set the Mosfet, Off
digitalWrite(LED1, HIGH);
for (int x=0; x < 500; x++) { // Wait for 1 second
delay(1); }
digitalWrite(LED1, LOW);
}
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("");
digitalWrite(LED2, HIGH);
for (int x=0; x < 2000; x++) { // Wait for 1 second
delay(1); }
digitalWrite(LED2, LOW);
}
mySwitch.resetAvailable();
}
}
A Library I found is a Timer library by simon Monk. I can make the code work, but not as part of my IF statement...