Basic Atom Help

This code is supposed to be make the always advance forward if there isn't any object infront. If there is any object in front then it should move back and do some sort of spin, but it's not working correctly. When an object is infront of it it just stops immeditately. It uses an IR sensor (Sharp 2d120x). Can anyone help me out with this code? I'm using basic atom pro...

low p10

low p11

m var word

mike var word

loop

ADIN p0, mike;

if mike < 200 then

gosub s

else

gosub l

endif

goto loop

s

for m=0 to 200

pulsout p10, 4000

pulsout p11, 2000

pause 20

next

return

l

for m=0 to 25

pulsout p11, -4000

pulsout p10, -4000

pause 20

next

return

It looks to be

It looks to be straitforward, is there a way to do a simulation of the code?

In the for loops, do you need to put a step value?

I would also recommend naming the subroutines to something a little more clear, like move_forward, move_backwards, things like that…it helps for readability.

If you can, I would put debug statements in various parts of the code. If the api doesn’t have doesn’t have a debug command, you could always send out the data via serial output.

for the sensor sub you could do something like(mind you this is an example and you’d need to use correct syntax)

adcout = varx ’ read the adc and put it in varX’

serialout(currently at sensor read, data out: varX) 'send output string with varX’

put stuff like this in each sub so you know it’s gone through that sub correctly and see where it stops.