How to use if between two values?

As topic, is there any way to use if between two values? I have only found exaples like

if (val <= 1400)digitalWrite(5, HIGH);

How can I use for example val between 1400 to 1700?

if ((x >=1400) && (x<= 1700))
3 Likes

Thanks, that did the work :slight_smile:

Do you also know how to get the diode on in two areas (4 values)

Like for example: 850 to 1300 and 1600 to 2000

Well it can't be in both ranges, so you'd need an ||

What does ll mean? I have tried with just adding another if sentence under, but that does not work

Adding an if statement under an if statement acts as a logical AND, and as AWOL said, you x cannot be in both ranges. It will either will fail the first if statement and never get to the second if statement or it will succeed the first if statement and fail the second if statement.

As AWOL said, use || which means logical OR

Your problem is "is x greater than or equal to 850 AND less than or equal to 1300 OR x is greater than or equal to 1600 AND x is less than or equal to 2000"

Now use this logical sentence to make your if statement