calculation in condition block of if else

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
geetansh
Posts: 29
Joined: Tue Jun 21, 2011 4:23 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

calculation in condition block of if else

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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: calculation in condition block of if else

Post 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"

geetansh
Posts: 29
Joined: Tue Jun 21, 2011 4:23 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: calculation in condition block of if else

Post by geetansh »

working fine now....
thanks.

Post Reply