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.
calculation in condition block of if else
- 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
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"
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"
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel