Você está na página 1de 4

#include <IRremote.

h>

int RECV_PIN = 3; // the pin where you connect the output pin of TSOP4838
int led1 = 2;
int led2 = 4;
int led3 = 5;
int led4 = 6;
int led5 = 7;
int led6 = 8;
int led7 = 9;
int led8 = 10;
int led9 = 11;
int led0 = 12;
int led11 = 13;

int itsONled[] = {0,0,0,0,0,0,0,0,0,0,0,0};

#define code1 33444015 // code received from button A


#define code2 33478695 // code received from button B
#define code3 33486855 // code received from button C
#define code4 33435855 // code received from button C
#define code5 33468495 // code received from button C
#define code6 33452175 // code received from button C
#define code7 33423615 // code received from button C
#define code8 33484815 // code received from button C
#define code9 33462375 // code received from button C
#define code0 33480735 // code received from button C
#define code11 33460335 // code received from button C

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led3,HIGH);
digitalWrite(led4,HIGH);
digitalWrite(led5,HIGH);
digitalWrite(led6,HIGH);
digitalWrite(led7,HIGH);
digitalWrite(led8,HIGH);
digitalWrite(led9,HIGH);
digitalWrite(led0,HIGH);
digitalWrite(led11,HIGH);

Serial.begin(9600);
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
pinMode(led9, OUTPUT);
pinMode(led0, OUTPUT);
pinMode(led11, OUTPUT);

void loop() {
if (irrecv.decode(&results)) {
unsigned int value = results.value;
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;
itsONled[4] = 1;
}
break;

case code5:
if(itsONled[5] == 1) {
digitalWrite(led5, LOW);
itsONled[5] = 0;
} else {
digitalWrite(led5, HIGH);
itsONled[5] = 1;
}
break;

case code6:
if(itsONled[6] == 1) {
digitalWrite(led6, LOW);
itsONled[6] = 0;
} else {
digitalWrite(led6, HIGH);
itsONled[6] = 1;
}
break;

case code7:
if(itsONled[7] == 1) {
digitalWrite(led7, LOW);
itsONled[7] = 0;
} else {
digitalWrite(led7, HIGH);
itsONled[7] = 1;
}
break;

case code8:
if(itsONled[8] == 1) {
digitalWrite(led8, LOW);
itsONled[8] = 0;
} else {
digitalWrite(led8, HIGH);
itsONled[8] = 1;
}
break;

case code9:
if(itsONled[9] == 1) {
digitalWrite(led9, LOW);
itsONled[9] = 0;
} else {
digitalWrite(led9, HIGH);
itsONled[9] = 1;
}
break;
case code0:
if(itsONled[0] == 1) {
digitalWrite(led0, LOW);
itsONled[0] = 0;
} else {
digitalWrite(led0, HIGH);
itsONled[0] = 1;
}
break;

case code11:
if(itsONled[11] == 1) {
digitalWrite(led11, LOW);
itsONled[11] = 0;
} else {
digitalWrite(led11, HIGH);
itsONled[11] = 1;
}
break;

}
Serial.println(value);
irrecv.resume();
}
}