Using IR remote to control Arduino functions.

Hello, Could anyone tell me how to solve this problem I'm having.

I've been using my arduino with the IR remote control libraries.
mapping the function of some remote control keys.
to hopefully use it to control some relays.

I managed to get an LED to turn on using this code:

/*
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>


const int led = 7;
const int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;



void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(led, OUTPUT);
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    
    if (results.value == 0xC03FE817) { // Power Button 
    digitalWrite(led, HIGH);
    
    }
      else if (results.value == 0xC03F6897) {
      digitalWrite(led,LOW);
      
    }    
    irrecv.resume(); 
 }
}

I can get the led to turn off but its using a different button on the remote. My question is how do I use the same button to turn the led either on or off?
I've tried a few different ways but none of them seem to work. My guess would be I need to store some variables as an boolean but I'm unsure how to implement to this.
Thank you very much.

Hi .

You nedd some extra variable for state of your led.

 int power_flag = 0;

And modify loop, Check this out:

    if (results.value == 0xC03FE817) { // Power Button 
      if(power_flag == 0){
        digitalWrite(led, HIGH);
        power_flag = 1;
      }
      else{
        digitalWrite(led,LOW); 
        power_flag = 0;
      } 
    }

Thank you very much that code seems to work!!
although the bracket quotes after the hex value 0xC03FE817) were not needed I guess you may have missed them.
All the best

Actually you are correct - the brackets after that if are not needed but neither do they do any harm and they do clearly delineate what is to happen should the 'if' be true. Good practice.