counter question

in BASIC Stamp
can someone explain to me why my code will not work without this counter line? im not understanding this for some reason. heres the code,
DO
counter=counter +1
IF counter>10 THEN
GOSUB pingout
ENDIF
IF (distance >30) THEN
GOSUB fwd
ELSE
GOSUB slowdown
ENDIF
LOOP
i didnt put in the subroutines but this is the main program. it will not work without the counter and im trying to figure out why. Thanks
DO
counter=counter +1
IF counter>10 THEN
GOSUB pingout
ENDIF
IF (distance >30) THEN
GOSUB fwd
ELSE
GOSUB slowdown
ENDIF
LOOP
i didnt put in the subroutines but this is the main program. it will not work without the counter and im trying to figure out why. Thanks
Comments
Without counter=counter+1 , your program will always fall through (via ELSE) to GOSUB slowdown.
In order to function properly, the Ping should have 20+ milliseconds between firings else you run the risk of incorrect readings.
pulsout esc, 775
pause 20
return
slowdown:
pulsout esc,550
pause 20
return
all it does right now is crawl fwd until it detects something then stops. im adding more and more steps one at a time to see how much it will do before slowing down. i wanted to know y i need the counter and cant just let it ping without it
Tom, Erco, and I are trying to help, and have asked several times for the complete code and yet we still do not have a complete picture.
pingout:
counter =0
low ping
pulsout ping,5
pulsin ping,1,distance
distance=distance**2257
return
now for now that is all of it. all i wanted to know was the purpose of the counter being here and what it does. thanks
So, initialise 'counter = 0' before DO, take 'counter = 0' out of the pingout subroutine and place it before or after 'GOSUB pingout'.