Multiple Boolean Conditions

Hi there,

could anyone just point out to me, why a statement such as:

if (conditionA && conditionB) || (conditionC) {
  // do This
}
else{
 // do That
}

would not work in the Arduino IDE?

I cannot find any reasonable explanation.

Thanks and best regards,
Jan

would not work in the Arduino IDE?

It would, and does. If the body of your statement is not being executed, it is because the conditions are never such that the whole statement evaluates to true.

Thanks for the fast answer Paul.
But actually i cant compile my sketch when I implement the if statement above. Anyhow, I thought it would be some limitation of the IDE.
I guess I have to dig some deeper now that I know that this should work in principle.

Best regards,
Jan

I guess I have to dig some deeper now that I know that this should work in principle.

The compiler produces some output. You could share that. The compiler can see your real code. We can't. You could share that.

if (conditionA && conditionB) || (conditionC)

I see a simple syntax error. Only the first expression is part of the if as it's enclosed in the first brackets.

Try

if ((conditionA && conditionB) || (conditionC))

Thanks for the help. I tried with the brackets, it would not compile either.
Here is the code I´m using:

 boolean simpleThread_loop(THREAD_LEDBlink)
  {
  /* Loop Function */
  if ((use_Relay_block == 1 && Relay_block == true) || (simpleThread_isRun(THREAD_InitControl) == true))
  {
    // take control over the LEDs
    LED_control = 1;
    // Dynamic Display showing a blinking call sign to signal user that relay is blocked 
    odd_even = !odd_even; // alternating operator used to display the call sign
      if (odd_even){ // Even
         digitalWrite(LEDPin_red, HIGH); // red LED off
      }
      else {  // Odd
         digitalWrite(LEDPin_red, LOW); // red LED off
      }
  }
  else{
    // Dont take control over the LEDs
    LED_control = 0;
  }
  return true;
  }

and that is the compiler error I get:

X_D_ThreadsFunctions.ino: In function 'boolean simpleThread_loop_THREAD_LEDBlink()':
X_D_ThreadsFunctions:377: error: expected `)' before ';' token
X_D_ThreadsFunctions:377: error: expected `)' before ';' token
X_D_ThreadsFunctions:377: error: expected primary-expression before '==' token
X_D_ThreadsFunctions:377: error: expected `;' before ')' token
Z_Loop:21: error: expected `}' at end of input

OK, I have taken you code and it compiles (after I have added dummy defines for all the global variables you use)

So the problem is probably that you have mismatched "{ }" or "( )" brackets somewhere else that confuses the compiler.

To find these place the cursor after a closing bracket and you should see a box around the matching beginning bracket. If it is not the one you expect it to be you have an error.

Thanks for the help Msquare,

I figure the problem is somewhere within the simpleThread_isRun() Function I´m using. So I guess I have to do some more pocking around. However, good to know that my initial sample (expanded by the brackets jimmy suggested) is a go.

Best regards,
Jan

You're welcome. I made no comment about its suitability or doing what you want it to do - only that it compiled, which you thought was your problem :wink:

Happy syntax hunting

What's happening here?

boolean simpleThread_loop(THREAD_LEDBlink)

Is THREAD_LEDBlink a type or variable name? If so, whichever it is is missing its other half. If not & it's a macro, hard to debug without seeing the full thing.

You also have to wonder how the compiler's error message has a different function name than is in the code!

In function 'boolean simpleThread_loop_THREAD_LEDBlink()'

Pete