Go Down

Topic: run command if analog read is within 2 values (Read 875 times) previous topic - next topic


Hello All!

I need to run a command, only if an analog pin is giving a value within f.ex. 600 and 700, or else run another commando. How do i do this in the easiest way? (the else part i know..)


Jul 03, 2012, 09:50 pm Last Edit: Jul 03, 2012, 09:52 pm by Arrch Reason: 1
Use the && operator in your if statement.

if ( (condition1) && (condition2) )

So it would be valid if it was less than 700 AND greater than 600. If you're checking "levels" (0-100, 200-300, 300-400, etc.), you could manage with else ifs and a single condition.


To be clear, you need two conditions.

This will not work:  "if (value > 100 && < 200)".

Instead it must be:  "if (value > 100) && (value < 200)".

In the 2nd you are using two conditionals and ANDing their result.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Go Up