Code:
symbol mot1p = b.7
symbol mot2p = b.5
symbol mot1n = b.6
symbol mot2n = b.4
symbol servop = b.0
symbol sharppin = c.0
symbol dist = b4
symbol lastturn = b1
lastturn = 0
main:
gosub distance
if dist > 60 and dist < 105 then
gosub driveforward
else
if lastturn = 0 then
gosub driveleft
else
gosub serv
gosub drivert
endif
endif
goto main
distance:
readadc sharppin, dist
return
serv:
servo b.0,75
wait 1
servo b.0,225
wait 1
servo b.0,150
pause 100
return
driveforward:
low mot2p high mot2n low mot1n high mot1p
return
drivebk:
high mot1n low mot1p high mot2n low mot2p
return
driveleft:
low mot2p high mot2n low mot1p high mot1n
lastturn = 1
return
drivert:
high mot2p low mot2n high mot1p low mot1n
lastturn = 0
return
sensor = sharp 2y0a21
I connected and programmed with the above code...the robo just turns right always..and it is not running forward..the sensor works fine [i tested it by debugging]...and when i tried unplugging the servo from power..then it works the way it is supposed to be..
so my doubts are
1)is it due to the noise from the servo which cause deflection in it?
2)what should i do to get rid of it?
3)is it harmful for my chip?
Attachments
-
184.3 KB Views: 34