Hi. I want to say the following:
if x ! (<70 && >5)
digitalWrite (LED, HIGH);
in words: I want LED to light if x is not between 5 and 70. I do need to use the “not” function because if I use a function like if x >70 || x <5 I do not get the LED to light if x = nan (like my temperature sensor got disconnected)
karotto:
Hi. I want to say the following:
if x ! (<70 && >5)
digitalWrite (LED, HIGH);
in words: I want LED to light if x is not between 5 and 70. I do need to use the “not” function because if I use a function like if x >70 || x <5 I do not get the LED to light if x = nan (like my temperature sensor got disconnected)
Thanks much
The entire expression must be within the parenthesis and your syntax is incorrect. But your premise is not entirely correct because every such expression has a complement that can be expressed without the negation:
if (not (x <70 && x>5) )
can be:
if (x >= 70 || x <= 5)
How a failed reading is reported depends on the sensor library code.
C provides >, <, ==, !=, <= and >= to compare numbers.
C provides parenthesis for grouping
C provides !, &&, and || to combine logical operators.
There isn’t a range function like “5 <= x <= 70” to check if x is between 5 and 70.
So, to check if a number is between 5 and 70, you use
(x >= 5) && (x <= 70)
To check the converse of this, x isn’t between 5 and 70 (inclusive)