Hi all, me again
I've been playing with the 28x1 project board this week in preparation for me eventually building an avoidance robot based on the LMR starter robot. I've had the servo moving around and I've used the pulsin and pulsout with the debug command to display the range on the screen.
I then tried adding an if....then to move a servo when the range gets below 10cm. I'm getting a syntax error on the if....then line?
I have coppied most of the code from the lmr site with the exception of the moving servo bit (which is where it went wrong!)
There's probably something obvious in there that I'm just not seeing
Thanks in advance
Paul
I've been playing with the 28x1 project board this week in preparation for me eventually building an avoidance robot based on the LMR starter robot. I've had the servo moving around and I've used the pulsin and pulsout with the debug command to display the range on the screen.
I then tried adding an if....then to move a servo when the range gets below 10cm. I'm getting a syntax error on the if....then line?
I have coppied most of the code from the lmr site with the exception of the moving servo bit (which is where it went wrong!)
Code:
symbol trig= 3 'define output pin for trigger pulse
symbol echo= 6 'define input pin for echo pulse
symbol range= w1 '16 bit word variable for range
main:
servo 0, 75 'move servo to far left
pulsout trig,2 'produce 20uS trigger pulse (must be minimum of 10Us)
pulsin echo,1,range 'measures the range in 10uS steps
pause 10 'recahrge period after ranging completes
'now convert range to cm (divide by 5.8) or inches (divide by 14.8)
'as picaxe cannot use 5.8, multiply by 10 then divide by 58 instead
let range = range*10/58 ' multiply by 10 then divide by 58
debug range 'display range via debug command
if range= <10 then movehead
goto main
movehead:
servo 0, 225 'move servo to far right
wait 3 'wait 3 seconds
goto main
Thanks in advance
Paul