IRremote sketch

hello guys , i have a IRremote module
i also found sketch for it , my questions is how to turn ON and OFF a LEDby pressing on the same button?

you can see n the sketch for the Led i use key 2 for ON and key 1 for OFF and i wat to make Led ON and OFF just by pressing key 1

thanks for help =)

here is the sketch i found and modified for some test:

#include "IRremote.h"

int receiver = 11; // Signal Pin of IR receiver to Arduino Digital Pin 11
int Led = 7;
int Led1 = 6;
/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);           // create instance of 'irrecv'
decode_results results;            // create instance of 'decode_results'

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  pinMode(Led, OUTPUT);
   pinMode(Led1, OUTPUT);
  Serial.begin(9600);
  Serial.println("IR Receiver Button Decode"); 
  irrecv.enableIRIn(); // Start the receiver

}/*--(end setup )---*/


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  if (irrecv.decode(&results)) // have we received an IR signal?

  {
    translateIR(); 
    irrecv.resume(); // receive the next value
  }  
}/* --(end main loop )-- */

/*-----( Function )-----*/
void translateIR() // takes action based on IR code received

// describing Remote IR codes 

{

  switch(results.value)

  {

  case 0xFF629D: digitalWrite(Led1, HIGH);  break; //pressing up button turn led on
  
  case 0xFF22DD: digitalWrite(Led, LOW);           //pressing left button turn both leds off
                 digitalWrite(Led1, LOW); 

  break; 
 
  case 0xFF02FD: digitalWrite(Led, HIGH);           //presing ok button turns both leds on
                 digitalWrite(Led1, HIGH); 

  break;  
  
  case 0xFFC23D: Serial.println(" RIGHT");   break;  //right
  
  case 0xFFA857: digitalWrite(Led1, LOW);  break;  //pressing down button turn led1 off
  
  case 0xFF6897: digitalWrite(Led, LOW);    break;    //pressing 1 button turn led off
  
  case 0xFF9867: digitalWrite(Led, HIGH);    break;  //pressing 2 button turn led on
  
  
  case 0xFFB04F: Serial.println(" 3");    break;     //3
  
  
  case 0xFF30CF: digitalWrite(Led1, HIGH);          //pressing 4 button turn led off and turn led1 on
                 digitalWrite(Led, LOW);
               




  break;     
  
  
  case 0xFF18E7: Serial.println(" 5");    break;     //5
  case 0xFF7A85: Serial.println(" 6");    break;     //6
  case 0xFF10EF: Serial.println(" 7");    break;
  case 0xFF38C7: Serial.println(" 8");    break;
  case 0xFF5AA5: Serial.println(" 9");    break;
  case 0xFF42BD: Serial.println(" *");    break;
  case 0xFF4AB5: Serial.println(" 0");    break;
  case 0xFF52AD: Serial.println(" #");    break;
  case 0xFFFFFFFF: Serial.println(" REPEAT");break;  

  default: 
    Serial.println(" other button   ");

  }// End Case

  delay(500); // Do not get immediate repeat


} //END translateIR



/* ( THE END ) */

Please read the first post in the section about posting (mainly because of the lack of code tags..)

Seconds, what is a LEDessing???

case 0xFF629D: //pressing up button turn led on/off
    if (digitalRead(Led1) == HIGH)
        digitalWrite(Led1, LOW);
    else
        digitalWrite(Led1, HIGH);  
break;

A shorter statement using the ternary operator ?:

case 0xFF629D: //pressing up button turn led on/off
    digitalWrite(digitalRead(Led1) == HIGH ? LOW : HIGH );
break;

@sept ok i will read the post sorry for that , and the LEDessing was just a mistype error i edited my post, thanks again =)

@marco_c thank you for your help i will try your code right away and i keep you updated =)

EDIT : ok now i can make a good code tags thanks to you sept =) and marco your first code worked like a charm but the second using ternary operator ? returned this error :

C:\Program Files\Arduino\Arduino ERW 1.0.5\hardware\arduino\cores\arduino/Arduino.h: In function 'void translateIR()':
C:\Program Files\Arduino\Arduino ERW 1.0.5\hardware\arduino\cores\arduino/Arduino.h:99: error: too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'
IRremote_led:42: error: at this point in file

This may be of interest to you:
http://forum.arduino.cc/index.php?topic=317625.0

thanks for the link larry i go check your link :slight_smile:

My mistake, but you should be able to fix it yourself ...

digitalWrite(Led1, digitalRead(Led1) == HIGH ? LOW : HIGH );

thanks marco. but i'm really new to coding , i got my arduino today please forgive me if i upset you but it's still hard for me to detect an error on a code :frowning:
anyway thanks again you helped me very much :slight_smile:

Not at all upset. If you are that new to the Arduino, then stick to the first if..then form as it will be clearer to you when you read it. Comes to the same thing.