#include <IRremote.h>
int IRremote = 13;
int firstlight = 3;
int secondlight = 4;
int thirdlight = 5;
int fourthlight = 6;
int led_case[] = {0,0,0,0};
IRrecv receiver(IRremote);
decode_results output;
#define code1 21212
#define code2 42590
#define code3 2928
#define code4 19938
void setup()
{
Serial.begin(9600);
receiver.enableIRIn();
pinMode(firstlight, OUTPUT);
pinMode(secondlight, OUTPUT);
pinMode(thirdlight, OUTPUT);
pinMode(fourthlight, OUTPUT);
}
void loop()
{
if (receiver.decode(&output))
{
unsigned int value = output.value;
switch(value)
{
case code1:
if(led_case[1] == 1)
{
digitalWrite(firstlight, LOW);
led_case[1] = 0;
}
else
{
digitalWrite(firstlight, HIGH);
led_case[1] = 1;
}
break;
case code2:
if(led_case[2] == 1)
{
digitalWrite(secondlight, LOW);
led_case[2] = 0;
}
else
{
digitalWrite(secondlight, HIGH);
led_case[2] = 1;
}
break;
case code3:
if(led_case[3] == 1)
{
digitalWrite(thirdlight, LOW);
led_case[3] = 0;
}
else
{
digitalWrite(thirdlight, HIGH);
led_case[3] = 1;
}
break;
case code4:
if(led_case[4] == 1)
{
digitalWrite(fourthlight, LOW);
led_case[4] = 0;
}
else
{
digitalWrite(fourthlight, HIGH);
led_case[4] = 1;
}
break;
}
Serial.println(value);
receiver.resume();
}
}