here is the code
this is more or less a blatent rip off of the start here bot code with some very minor modification.
BTW I want to learn C for arduino does any body have this basic functionality in arduino C I could look at?
Symbol distance = 70 ’ are we going to run into something?
symbol turn = 200 ’ chassis turn duration
symbol servo_time = 200 ’ how long for server to turn ir sensor
main: ’ the main loop
readadc 0, b1 ’ how far is the closest obstacle
if b1 < distance then
gosub allclear ’ clear to move forward
else
gosub direction ’ if obstacle ahead then decide which way is better
end if
goto main ’ end loop
allclear:’ both motors forward
high 4 : high 7 : low 5 : low 6
return
direction:
gosub totalhalt ’ stop all motors
'look left
gosub lturn ’ look to one side
pause servo_time ’ wait for servo turn
readadc 0, b1
gosub totalhalt
'look right
gosub rturn
pause servo_time ’ wait for servo turn
readadc 0, b2
gosub totalhalt
’ Decide which is the better way:
if b1<b2 then
gosub body_lturn
else
gosub body_rturn
end if
return
body_lturn:
high 6 : low 5 : low 7 : high 4 ’ right motor forward left motor backward
pause turn : gosub totalhalt
return
body_rturn:
high 5 : low 6 : low 4 : high 7 ’ left motor forward right back
pause turn : gosub totalhalt
return
rturn:
servo 0, 100 ’ turn servo right
return
lturn:
servo 0, 200 ’ turn servo left
return
totalhalt:
low 4 : low 5 : low 6 : low 7 ’ stop all motors
Servo 0,150 ’ servo center
wait 1 ’ wait 1 secd
return