Ping sensor with Pic 16f877a problem!!
ricorimto
Posts: 1
hello,
i 've connected ping sensor with pic 16f877a and one servo , trying to make the servo stops every time the ping detects objects, here's the code i'm using with picbasic :
main:
i var byte
distance var byte
cms var byte
trisb=0
run:
servo:
for i =0 to 174
pulsout 7,170
pause 20
next i
gosub getdistance
if cms <40 then stopservo
goto servo
getdistance:
low 1
pulsout 1,1
low 1
pulsin 1,1,distance
distance=distance/2
cms=distance*9
return
stopservo:
pulsout 7,150
pause 5000
goto run
end
please help!!!
i 've connected ping sensor with pic 16f877a and one servo , trying to make the servo stops every time the ping detects objects, here's the code i'm using with picbasic :
main:
i var byte
distance var byte
cms var byte
trisb=0
run:
servo:
for i =0 to 174
pulsout 7,170
pause 20
next i
gosub getdistance
if cms <40 then stopservo
goto servo
getdistance:
low 1
pulsout 1,1
low 1
pulsin 1,1,distance
distance=distance/2
cms=distance*9
return
stopservo:
pulsout 7,150
pause 5000
goto run
end
please help!!!
Comments
might be better off looking something like this...
...Also, you might want to increase cms to a WORD value
...similar to how you have it in the regular servo routine.