I think I'm getting pretty close, but I am not quite sure what I should be putting for the switch(state) part, I beleive I need to change state to be looking for somthing else, I tried value, but that didn't work.
Looking at the serial feed with the code as follows it is turning itself off before it starts, it is picking up the various button presses and entering the right value, but before it can act the state is set back to STATE_MOSFET_SWITCH_OFF...
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
//STATE INSTRUCTIONS//
#define STATE_MOSFET_OFF 0
#define STATE_MOSFET_SWITCH_ON 1
#define STATE_MOSFET_ON 2
#define STATE_MOSFET_SWITCH_OFF 3
//VARIABLES//
#define BUTTON1 7419184
#define BUTTON2 7419139
#define theMOSFET 10 // Pin that activates your Mosfet
#define REDLED 4
#define GRNLED 6
#define RUNTIME 2700000 /// 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(theMOSFET, OUTPUT);
pinMode(REDLED, OUTPUT);
pinMode(GRNLED, OUTPUT);
}
void loop(){
if (mySwitch.available()); {
unsigned long value = mySwitch.getReceivedValue();
static unsigned char state = STATE_MOSFET_OFF;
static unsigned long timer = 0;
switch(state)
{
case STATE_MOSFET_SWITCH_ON:
digitalWrite(theMOSFET,HIGH);
digitalWrite(GRNLED,HIGH);
Serial.print("Mosfet Run - button: "); // This and the next three lines are for debug and testing purposes
Serial.println(mySwitch.getReceivedValue() );
state = STATE_MOSFET_ON;
timer = millis();
break;
case STATE_MOSFET_SWITCH_OFF:
Serial.print("Mosfet Off - button: "); // This and the next two lines are for debug and testing purposes
Serial.println(mySwitch.getReceivedValue() );
digitalWrite(theMOSFET,LOW);
digitalWrite(GRNLED,LOW);
state = STATE_MOSFET_OFF;
break;
case STATE_MOSFET_ON:
if(millis() - timer > 5000)
state = STATE_MOSFET_SWITCH_OFF;
break;
}
if(value==BUTTON1);
{
state = STATE_MOSFET_SWITCH_ON;
}
if(value==BUTTON2);
{
state = STATE_MOSFET_SWITCH_OFF;
}
mySwitch.resetAvailable();
}
}
Close but no cigar, am going to look at it again tomorrow once I have a fresh head.
Thanks all for your help so far, sorry if i'm a bit slow picking it up, C is a new language for me.