Hi!
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 &
Is there other command for AND in ESP32?
****** SOLVED***** Search in the net, USE &&
Thank´s in advance
Jorgen
AND function in ESP32! SOLVED! Use && instead
-
- Posts: 615
- http://meble-kuchenne.info.pl
- Joined: Thu Dec 03, 2020 8:25 pm
- Location: Denmark
- Has thanked: 507 times
- Been thanked: 132 times
-
- Matrix Staff
- Posts: 1451
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 512 times
- Been thanked: 472 times
Re: AND function in ESP32! SOLVED! Use && instead
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
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
Martin
-
- Posts: 615
- Joined: Thu Dec 03, 2020 8:25 pm
- Location: Denmark
- Has thanked: 507 times
- Been thanked: 132 times
Re: AND function in ESP32! SOLVED! Use && instead
Hi MArtin!
Thank you very much. Learn some new today
So AND versus is not equal to && I have earlyer used OR and AND in Arduino and Pic whith good luck.
Thank´s again I will be aware in the future
Br Jorgen
Thank you very much. Learn some new today
So AND versus is not equal to && I have earlyer used OR and AND in Arduino and Pic whith good luck.
Thank´s again I will be aware in the future
Br Jorgen
-
- Matrix Staff
- Posts: 1451
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 512 times
- Been thanked: 472 times
Re: AND function in ESP32! SOLVED! Use && instead
Hi Jorgen,
Your'e welcome.
The AND OR NOT etc for bit wise manipulation only.
Your'e welcome.
No definitely not the same.
The AND OR NOT etc for bit wise manipulation only.
Martin
-
- Matrix Staff
- Posts: 1253
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 167 times
- Been thanked: 277 times
Re: AND function in ESP32! SOLVED! Use && instead
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).
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).
-
- Posts: 615
- Joined: Thu Dec 03, 2020 8:25 pm
- Location: Denmark
- Has thanked: 507 times
- Been thanked: 132 times
Re: AND function in ESP32! SOLVED! Use && instead
Hi Martin and Steve!
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.
But please tell me, why sometime use two &,|.
Eks:
If A & B =2
If A && B =2
Br Jorgen
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.
But please tell me, why sometime use two &,|.
Eks:
If A & B =2
If A && B =2
Br Jorgen
-
- Matrix Staff
- Posts: 1253
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 167 times
- Been thanked: 277 times
Re: AND function in ESP32! SOLVED! Use && instead
Single is boolean operation: "10 & 7" => 2
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!
-
- Valued Contributor
- Posts: 401
- Joined: Mon Dec 07, 2020 1:00 pm
- Has thanked: 71 times
- Been thanked: 217 times
Re: AND function in ESP32! SOLVED! Use && instead
This one is very good, which explains its top ranking
https://www.tutorialspoint.com/cprogram ... rators.htm
https://www.tutorialspoint.com/cprogram ... rators.htm
-
- Posts: 615
- Joined: Thu Dec 03, 2020 8:25 pm
- Location: Denmark
- Has thanked: 507 times
- Been thanked: 132 times
Re: AND function in ESP32! SOLVED! Use && instead
Thank you Leigh. As Steve said Google it ,I am in full speed and begin to understand
I will have a look at your link, thank you and have a nice weekend.
Br Jorgen
I will have a look at your link, thank you and have a nice weekend.
Br Jorgen