Skip to main content

switch case problem of ardiuno code

I am trying to developed IR remote for appliances. I have made a arduino code for this puspose.I have used switch case for particular action to 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 
//int led2 = 11; //1FEF807
////int led3 = 10;//1FE3087
//int led4 = 9;//1FEB04F

boolean previousState=LOW;
boolean previousState1=LOW;
//boolean previousState2=LOW;
//boolean previousState3=LOW;
//boolean previousState4=LOW;
boolean state;
boolean state1;
//boolean state2;
//boolean state3;
//boolean state4;
IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  pinMode(13,OUTPUT);
  pinMode(12,OUTPUT);
  //pinMode(10,OUTPUT);
  //pinMode(9,OUTPUT);
 // pinMode(8,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;
        /*case '0x1FEF807':
       if (previousState2 == LOW)
       {state2=HIGH;
       digitalWrite(led2,state2);
       previousState2=state2;}
       else
       {state2=LOW;
       digitalWrite(led2,state2);
       previousState2=state2;}
       break;
        case '0x1FE3087':
       if (previousState3 == LOW)
       {state3=HIGH;
        digitalWrite(led3,state3);
       previousState3=state3;}
       else
       {state3=LOW;
       digitalWrite(led3,state3);
       previousState3=state3;}
       break;
        case '0x1FEB04F':
       if (previousState4 == LOW)
       {state4=HIGH;
        digitalWrite(led4,state4);
       previousState4=state4;}
       else
       {state4=LOW;
       digitalWrite(led4,state4);
       previousState4=state4;}
       break;*/
    }   
    irrecv.resume(); // Receive the next value
  }
}
Prayuktibid
  • 362
  • 1
  • 5
  • 18