#include <IRremote.
h>
int RECV_PIN = 10; // Connect your IR reciever to this pin
int led1 = 5;
int led2 = 6;
int led3 = 7;
int led4 = 8;
int itsONled[] = {0,1,0,0};
/* the initial state of LEDs is OFF (zero)
the first zero must remain zero but you can
change the others to 1's if you want a certain
led to light when the board is powered */
#define code1 33 // Code revieved from your 1st button
#define code2 16417 // Code revieved from your 2nd button
#define code3 8225 // Code revieved from your 3rd button
#define code4 24609 // Code recieved from your 4th button
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
[Link](9600); // you can ommit this line
[Link](); // Start the receiver
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void loop() {
if ([Link](&results)) {
unsigned int value = [Link];
switch(value) {
case code1:
if(itsONled[1] == 1) { // if first led is on then
digitalWrite(led1, LOW); // turn it off when button is pressed
itsONled[1] = 0; // and set its state as off
} else { // else if first led is off
digitalWrite(led1, HIGH); // turn it on when the button is pressed
itsONled[1] = 1; // and set its state as on
}
break;
case code2:
if(itsONled[2] == 1) {
digitalWrite(led2, LOW);
itsONled[2] = 0;
} else {
digitalWrite(led2, HIGH);
itsONled[2] = 1;
}
break;
case code3:
if(itsONled[3] == 1) {
digitalWrite(led3, LOW);
itsONled[3] = 0;
} else {
digitalWrite(led3, HIGH);
itsONled[3] = 1;
}
break;
case code4:
if(itsONled[4] == 1) {
digitalWrite(led4, LOW);
itsONled[4] = 0;
} else {
digitalWrite(led4, HIGH);
itsONled[4] = 1;
}
break;
}
[Link](value); // you can ommit this line
[Link](); // Receive the next value
}
}