Let's Make Robots!

Arduino C, IF/THEN IF/ELSE with ranges

How do you define a value range in an IF statement?  I.E.  IF  analog.Read1 >= between 3 and 5  THEN do something

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

while(girl==ugly){
drink++;

 

 


if ((val >= 3) && (val <=5))   {

      Serial.print("Within range");

    }
   
    else {
      Serial.print("outside of range");
      }


 

Something like

IF analog.Read1 > 3 AND analog.Read1 < 5 THEN ...

Opps, forgot the equal part.. Rudolph didn't though.

maybe-semi-pseudo-code (don't recall analogRead() syntax right now)

int val = analogRead(pinNumber);

if((val >= 3) && (val <= 5)){

    // val is 3 or 4 or 5

}

 

edit = oops, I think it's "&&", not "and"