Power Toggle

Hi I am currently working on a little home automation project where I am using an old VHS remote for the control of the power to the outlets in my room as well as my ceiling fan/light by toggling a relay.

Currently I press the power button on the remote to turn on the power to the outlets and press the eject button to turn it back off.

I have tried to figure it out on my own and have sadly failed but my goal is to be able to use the same button to turn on and off the power. If anyone has some suggestions or advice with the code I'd love to hear it, Thanks

Here is the basic code I have so far that just toggles the lights as well as the power.

#include <IRremote.h>//includes IR library

int RECV_PIN = 11; //IR input
int Light1 = 7;                   // Pin 7 used for relay
int Light2 = 6;                   // Pin 6 used for relay
int Power = 5;                    // pin 5 used for relay

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
irrecv.enableIRIn(); // Start the receiver
pinMode(Light1, OUTPUT);        // declare pin 7 to be an output
pinMode(Light2, OUTPUT);        // declare pin 6 to be an output
pinMode(Power, OUTPUT);         // declares pin 5 as an output
}

void loop() 
{
if (irrecv.decode(&results)) //revieves IR info
{
irrecv.resume(); // Receive the next value
}
delay(100);
if (results.value == 31377463)//if power button is hit then do the following
{
digitalWrite(Power,HIGH);
} 
if(results.value == 31355533)//if eject button is pressed turn off power
{
digitalWrite(Power,LOW);//turn off power
} 
if (results.value == 31352983)//if play button is hit then do the following
{
digitalWrite(Light1,HIGH);//turn on wire 1
digitalWrite(Light2,HIGH);//turn on wire 2
}
 if (results.value == 31385623)//if stop button is hit then do the following
{
digitalWrite(Light1,LOW);//turn off wire 1
digitalWrite(Light2,LOW);//turn off wire 2
}

I know it may seem simple to you but it isn't to me so if you can help thanks if not that's fine.

I have tried to figure it out on my own and have sadly failed but my goal is to be able to use the same button to turn on and off the power.

Sounds ridiculously simple. All you need to do is keep track of whether the power is on or off. If it is on, turn it off. If it is off, turn it on.

delay(100);//delays 100 miliseconds

Really? Comments that state the obvious add no value.

Welcome to the Forum. Please read the two posts at the top of this Forum by Nick Gammon on guidelines for posting here, especially the use of code tags ("</>") when posting source code files. Also, before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read.

If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button.