Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Mini-Skybot
- 'ossipee
- symbol motorR = 1 ; call pin for right motor
- symbol motorL = 2 ; call pin for left motor
- symbol motorRC = 145 ; stop motor
- symbol motorLC = 147 ; stop motor
- symbol trigger = 0 ; call pin that send pulse
- symbol echo = 4 ; call pin that gets pulse back
- symbol tm = w1 ;variable for microseconds read off of HCSR04
- symbol inches = w2; variable for converting microseconds to distance, about 15 us/in
- symbol dangerL = 7 ;arbitrary safe distance to obstacles-make it lower than you'd think
- symbol leftObstacle = w3; variable to store distance read when looking left
- symbol rightObstacle = w4; variable to store distance read when looking right
- servo motorR,motorRC ; set pins as servo outputs
- servo motorL,motorLC
- pause 3000 ; wait 3 seconds to start
- main:
- gosub myHCSR04
- if inches > dangerL then ; safe go forward
- gosub nodanger ; go forward
- else
- gosub whichway ; look how to go
- endif
- goto main
- myHCSR04:
- pulsout C.0,1; sends 20us pulse out to ping
- pulsin C.4,1,tm ; measures range in 10us steps
- inches = tm/15
- pause 100
- return
- nodanger:
- servopos motorR,225
- servopos motorL,75
- return
- whichway:
- gosub totalhalt ; stop everything for crash
- gosub turnleft ; turn left
- pause 780; for 3/4 second or 90 degrees left depending on your servos
- gosub totalhalt; stop
- gosub myHCSR04; to take reading
- leftObstacle = inches;
- gosub turnright ; turn right
- pause 1500 ; for 1.5 seconds or 180 degrees right depending on your servos
- gosub totalhalt; stop
- gosub myHCSR04; to take reading
- rightObstacle = inches
- if leftObstacle > rightObstacle then; if the left obstacle is more distant than the right
- gosub turnleft; go back around to the left
- pause 1560; for 1.5 seconds or 180 degrees
- else
- return; no need to turn if the right obstacle is more distant
- endif
- return
- turnleft:
- servopos motorR, 75
- servopos motorL, 75
- return
- turnright:
- servopos motorR, 225
- servopos motorL, 225
- return
- totalhalt:
- servopos motorR, 145
- servopos motorL, 147
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement