Friday, 30 April 2010

Using Conditional Statements and Functions

main:

readadc 1,b1
debug b1
readadc 2,b2
debug b2

if b1>200 and b2<200
goto turnL

if b1<200 and b2>200
goto turnR

else
goto front

front: ;this is when the ldrs dont detect any change

low 1
high 2
low 3
high 4
goto main

turnR: ;this is when the rite lrd is on the black line

high 1
low 2
low 3
high 4

turnL: ; when the left ldr is on the lack line

low 1
high 2
low 3
low 4
goto main



The idea of this program was that when the ldr detects a black line it sends a signal to the microcontroller asking it to stop one of the motors , so that the buggy turns and stays on the path.

For example when the left ldr will come over the black line, it will send a signal to the microcontroller asking it to stop the left motor. on stoping the left motor the left wheel will become stationary and the right wheel will make the buggy turn. so in this way the buggy will stay on the path and will follow the line
similarly when the right ldr is over the black line it will send a signal to the controller asking it to stop the left motor so that the buggy turns right. If the ldrs dont face any black strip it would continue to move forward as no signal will be send to the controller and the wheels would continue to rotate as they are

1 comment:

  1. With only two sensors and comparing these to absolute terms you will be vulnerable to local changes in light conditions. Better to use a three or more sensor system which possibly makes comparisons not based on a single reading but on eg. relative differences in the sensor reading and on how each sensor reading changes in time.

    ReplyDelete