Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. '{$STAMP BS2}
  2. '{$PBASIC 2.5}
  3.  
  4. TURNON CON 1
  5. TURNOFF CON 0
  6. DARK CON 0
  7. LIGHT CON 1
  8. counter var byte
  9. '----------------
  10. 'initialization
  11.  
  12. OUTPUT 11
  13. initLed VAR OUT11
  14.  
  15. 'blink the LED
  16. initLED = TURNON
  17. PAUSE 500
  18. initLed = TURNOFF
  19. PAUSE 500
  20.  
  21. 'beep the piezospeaker
  22. FREQOUT 10, 500, 2637
  23. pause 10
  24.  
  25. '----------------------------
  26.  
  27. capacitorTime var word
  28. INPUT 1
  29. INPUT 6
  30. pr var in6
  31.  
  32.  
  33. 'main program
  34. main:
  35. DO
  36.  
  37. GOSUB checkValue
  38. GOSUB check
  39. LOOP
  40.  
  41.  
  42.  
  43.  
  44.  
  45. 'subroutines
  46. checkValue:
  47. high 6
  48. pause 1
  49. RCTIME 6,1,capacitorTime
  50. DEBUG ? capacitorTime
  51. RETURN
  52.  
  53. check:
  54. IF capacitorTime > 9 THEN
  55. GOSUB turnleft
  56. GOSUB reCheck
  57. ELSE
  58. GOSUB moveForward
  59. ENDIF
  60. RETURN
  61.  
  62. reCheck:
  63. DO UNTIL capacitorTime < 9
  64. GOSUB turnRight
  65. LOOP
  66. RETURN
  67.  
  68. moveForward:
  69. for counter = 1 to 2
  70. PULSOUT 12, 810
  71. PULSOUT 13, 700
  72. pause 20
  73. NEXT
  74. GOSUB checkValue
  75. RETURN
  76.  
  77. stopMove:
  78. pause 100
  79. RETURN
  80.  
  81. turnLeft:
  82. for counter = 1 to 4
  83. PULSOUT 12, 650
  84. PULSOUT 13, 650
  85. pause 20
  86. NEXT
  87. GOSUB stopMove
  88. RETURN
  89.  
  90. turnRight:
  91.  
  92. for counter = 1 to 2
  93. PULSOUT 12, 790
  94. PULSOUT 13, 790
  95. PAUSE 20
  96. NEXT
  97. GOSUB checkValue
  98. RETURN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement