I am playing with a project with an Ili9341 and an ESP32 with XPT2046
If I use an IF contain this: X > 34 AND X < 130 AND Y > 110 AND Y < 65 I get an error when compiling look like the ESP32 don´t like AND. It work with arduino and Arm I also try with &
Hi, Jorgen.
Just to clarify, You always use && instead of AND in any decisions when comparing values.
&& is Logical.
AND is bitwise.
Also for when comparing values use the following logical operators:
|| = OR (| is the pipe key next to Z on a UK keyboard).
! = NOT
The bitwise AND (&) can sometime appear to work like the logical &&, but not always. I think it's always safer to avoid "AND", "OR", etc., and always use the correct symbol (e.g. & or &&) to avoid confusion.
For example, consider three byte variables (X=1, Y=2, Z=3) in the following decisions:
"if (X & Y)" is false, but "if (X & Z)" is true (the bitwise operator results in "if 0" and "if 1" respectively).
"if (X && Y)" is true, and "if (X && Z)" is true (X, Y and Z are all non-zero and converted to "true" when using the logical operators).
Thank you very much. Yes , I though it doesn´t matter how to use And as Steve said it sometimes work I Expeince it work with AND OR ect. It have always used this. I am glad to know your explanation and of course, from now always use you advice.
Double is a logical operation: "true && false" => false
A further complication is that in logical operations (e.g. in the decision icon) any non-zero number is converted to "true" and zero is converted to "false". So "if (10 & 7)" becomes "if (2)" which becomes "if (true)".
But "if (10 & 5)" becomes "if (0)" which becomes "if (false)".
But Leigh is correct - there are lots of better explanations elsewhere on the internet!