I am trying to develop an IR remote for appliances. I have written Arduino code for this purpose. I have used switch case to determine an action from the corresponding IR decode result (HEX), but I am not getting the output.
My code is:
#include <IRremote.h>
int RECV_PIN = 6;
int led = 13;//1FE50AF
int led1 = 12;//1FED827
boolean previousState=LOW;
boolean previousState1=LOW;
boolean state;
boolean state1;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
irrecv.enableIRIn();// Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
switch(results.value) {
case '0x1FE50AF':
if (previousState == LOW) {
state=HIGH;
digitalWrite(led,state);
Serial.println("LED ON");
previousState=state;
} else {
state=LOW;
digitalWrite(led,state);
Serial.println("LED Off");
previousState=state;
}
break;
case '0x1FED827':
if (previousState1 == LOW) {
state=HIGH;
digitalWrite(led1,state1);
Serial.println("LED ON");
previousState1=state1;
} else {
state1=LOW;
digitalWrite(led1,state1);
Serial.println("LED off");
previousState1=state1;
}
break;
}
irrecv.resume(); // Receive the next value
}
}