Skip to main content
Fix typo
Link
per1234
  • 4.2k
  • 2
  • 23
  • 43

Switch case problem in ArdiunoArduino code

Spelling, grammar, code formatting
Source Link
jfpoilpret
  • 9.1k
  • 7
  • 37
  • 54

I am trying to develop an IR remote for appliances. I have wrotewritten Arduino code for this purpose. I have used switch case forto determine an action from the corresponding IR decode result (HEX), but I am not getting the output. My

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
  }
}

I am trying to develop an IR remote for appliances. I have wrote Arduino code for this purpose. I have used switch case for 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
  }
}

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
  }
}

switch Switch case problem of ardiunoin Ardiuno code

I am trying to developeddevelop an IR remote for appliances. I have made a arduinowrote Arduino code for this pusposepurpose.I I have used switch case for particulardetermine an action tofrom the corresponding IR decode result  (HEX)but, 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
  }
}

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
  }
}

Switch case problem in Ardiuno code

I am trying to develop an IR remote for appliances. I have wrote Arduino code for this purpose. I have used switch case for 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
  }
}
markdown code
Source Link
jfpoilpret
  • 9.1k
  • 7
  • 37
  • 54
Loading
Source Link
Prayuktibid
  • 362
  • 1
  • 5
  • 18
Loading