Pages: [1]   Go Down
Author Topic: run command if analog read is within 2 values  (Read 536 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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..)
Logged

California
Online Online
Faraday Member
**
Karma: 92
Posts: 3442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 03, 2012, 02:52:49 pm by Arrch » Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Aha. Nice.

Thanks smiley-grin
Logged

Pages: [1]   Go Up
Jump to: