Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' {$STAMP BS2} ' Stamp directive.
  2. ' {$PBASIC 2.5} ' PBASIC directive.
  3. DEBUG "Program Running!"
  4. ' -----[ Variables ]----------------------------------------------------------
  5. pulseCount VAR Byte ' FOR...NEXT loop counter.
  6. ' -----[ Initialization ]-----------------------------------------------------
  7. FREQOUT 4, 2000, 3000 ' Signal program start/reset.
  8. ' -----[ Main Routine ]-------------------------------------------------------
  9. DO
  10.  IF (IN5 = 0) AND (IN7 = 0) THEN ' Both whiskers detect obstacle
  11.  GOSUB Back_Up ' Back up & U-turn (left twice)
  12.  GOSUB Turn_Left
  13.  GOSUB Turn_Left
  14.  ELSEIF (IN5 = 0) THEN ' Left whisker contacts
  15.  GOSUB Back_Up ' Back up & turn right
  16.  GOSUB Turn_Right
  17.  ELSEIF (IN7 = 0) THEN ' Right whisker contacts
  18.  GOSUB Back_Up ' Back up & turn left
  19.  GOSUB Turn_Left
  20.  ELSE ' Both whiskers 1, no contacts
  21.  GOSUB Forward_Pulse ' Apply a forward pulse
  22.  ENDIF ' and check again
  23. LOOP
  24. ' -----[ Subroutines ]--------------------------------------------------------
  25. Forward_Pulse: ' Send a single forward pulse.
  26.  PULSOUT 13,850
  27.  PULSOUT 12,650
  28.  PAUSE 20
  29.  RETURN
  30. Turn_Left: ' Left turn, about 90-degrees.
  31.  FOR pulseCount = 0 TO 20
  32.  PULSOUT 13, 650
  33.  PULSOUT 12, 650
  34.  
  35.  PAUSE 20
  36.  NEXT
  37.  RETURN
  38. Turn_Right:
  39.  FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
  40.  PULSOUT 13, 850
  41.  PULSOUT 12, 850
  42.  PAUSE 20
  43.  NEXT
  44.  RETURN
  45. Back_Up: ' Back up.
  46.  FOR pulseCount = 0 TO 40
  47.  PULSOUT 13, 650
  48.  PULSOUT 12, 850
  49.  PAUSE 20
  50.  NEXT
  51.  RETURN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement