Switch...case "label" "||" "label" two case single function?

Hello all, I am looking to use two labels for a case function - so that two separate IR remote HEX's can trigger the same function , I have tried "or" and "||" without any luck. Is this possible? I cannot simply add another case as it is nested in a "else"/"else if" case at the end of my switch.

       case 0x76A77416 || 0x169E8AEE:
        if (v >= 5){
          pausev = v;
          delay(100);
          v = 0;
          lcd.setCursor(55, 0);
          lcd.setFontSize(FONT_SIZE_MEDIUM);
          lcd.setCursor(55, 0);
          lcd.println("     ");
          lcd.setCursor(55, 0);
          lcd.println("P CENTER");
          }
        else if (v < 5){
          v = 0x76A77416 || 0x169E8AEE;
          delay(100);
          lcd.setCursor(55, 0);
          lcd.setFontSize(FONT_SIZE_MEDIUM);
          lcd.setCursor(55, 0);
          lcd.println("        ");
          lcd.setCursor(70, 0);
          lcd.println(bpm);
          lcd.setCursor(110, 0);
          lcd.println("<>");
case 0x76A77416:
case 0x169E8AEE:
2 Likes

in your code 0x76A77416 || 0x169E8AEE is a boolean logic expression.

As anything non null is true, you are doing true || true which is true. As the switch case expects a integral value, then this value is promoted to its integral representation which is 1 so it's like you had written

case 1:
        if (v >= 5){
          pausev = v;
          delay(100);
...
1 Like

That means "case 1:" because 0x76A77416 is 'true' (!= 0) and 0x169E8AEE is 'true' (!= 0) and "true || true" is true (1).

1 Like

Allowed data types: int , char .
label1 , label2 : constants. Allowed data types: int , char .

0x76A77416 is more then int ..no? Even if youre case is;
case 0x76A77416:

Thank you all, I think I understand why it does not work now but I fail to understand if and how it can work. I am not an expert in this area (as I am sure you correctly guessed:), I do appreciate your help understanding the problem.

See the answer from '...AWOL' in reply #2.

Thanks John, I tried that but it only works for the first cycle.

case 0x76A77416:
       case 0x169E8AEE:
        if (v >= 5){
          pausev = v;
          delay(100);
          v = 0;
          lcd.setCursor(55, 0);
          lcd.setFontSize(FONT_SIZE_MEDIUM);
          lcd.setCursor(55, 0);
          lcd.println("     ");
          lcd.setCursor(55, 0);
          lcd.println("P CENTER");
          }
        else if (v < 5){
          v = 0x76A77416, 0x169E8AEE;
          delay(100);
          lcd.setCursor(55, 0);
          lcd.setFontSize(FONT_SIZE_MEDIUM);
          lcd.setCursor(55, 0);
          lcd.println("        ");
          lcd.setCursor(70, 0);
          lcd.println(bpm);
          lcd.setCursor(110, 0);
          lcd.println("<>");

Sorry, corrected: (but still not working, 0x169E8AEE does not trigger function)

       case 0x76A77416:
       case 0x169E8AEE:
        if (v >= 5){
          pausev = v;
          delay(100);
          v = 0;
          lcd.setCursor(55, 0);
          lcd.setFontSize(FONT_SIZE_MEDIUM);
          lcd.setCursor(55, 0);
          lcd.println("     ");
          lcd.setCursor(55, 0);
          lcd.println("P CENTER");
          }
        else if (v < 5){
          v = pausev;
          delay(100);
          lcd.setCursor(55, 0);
          lcd.setFontSize(FONT_SIZE_MEDIUM);
          lcd.setCursor(55, 0);
          lcd.println("        ");
          lcd.setCursor(70, 0);
          lcd.println(bpm);
          lcd.setCursor(110, 0);
          lcd.println("<>");

I just ran IR_Receive_Demo_3.1 to double check the hex, I get this error for only this remote button:

Space between two detected transmission is greater than 5000 but smaller than the minimal gap of 20000 known for a protocol.
Try to increase the RECORD_GAP_MICROS in IRremote.h.

Seems to be the problem.

I am looking for it now in the file.

that's not what the standard says

any expression of integral or enumeration type, or of a class type contextually implicitly convertible to an integral or enumeration type, or a declaration of a single non-array variable of such type with a brace-or-equals initializer.

=> So a uin32_t is fine

1 Like

Another example of the Arduino reference being deficient.

I had to step out for a few minutes. It looks like the button in question needs a RECORD_GAP_MICROS setting of 15000 - which is way too high for the other buttons to work. This planned function was very minor, so I am just going to omit it, it's probably not worth what it may take to resolve this - if it even can be with my knowledge. Thank you all for your help, we did find the problems:). -Travis

What did you expect this to do?

Uh-oh

I just copied and pasted the HEX into the wrong line and did not catch it until I was comparing an old version of the script to the current version.

Different Travis, I have not messed with ethernet on arduino yet - although I do have a weather station.