Page 1 of 1

calculation in condition block of if else

Posted: Wed Jan 04, 2012 11:47 am
by geetansh
i m working on an AGV, there r 3 LDR on th front,right and left to sense light. voltage across ldr is read n converted into interger.
front_ldr , right_ldr , left_ldr are values ranging from 0-1023
now the problem is with if-else conditions.
suppose light coming on front and left side is approx. equal so it should turn little left
if(left_ldr-10<front_ldr<left_lrd+10)
then "turn left"

but this left_ldr-10<front_ldr<left_lrd+10 is not working, simulation is showing it is always true whether i change adc input or not.
please help
tell me how to check whether on of the ldr value is nearby(plus minus 10) of another ldr value.

Re: calculation in condition block of if else

Posted: Wed Jan 04, 2012 12:07 pm
by Benj
Hello,

You may have to do something like this instead. I have added some brackets and also made it so that each comparison is only using 2 values and then joined together using the double ampersand.

if( ((left_ldr-10) < front_ldr ) && ( front_ldr < (left_lrd+10)) )
then "turn left"

Re: calculation in condition block of if else

Posted: Wed Jan 04, 2012 1:29 pm
by geetansh
working fine now....
thanks.