Page 192 ·
Robotics with the Boe-Bot
' Robotics with the Boe-Bot - CirclingWithWhiskerInput.bs2
' Move in 1 yard circle, increase/decrease radius in response
' to whisker presses, one whisker increases, one decreases.
' {$STAMP BS2} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
DEBUG "Program Running!"
' -----[ Variables/Initialization ]------------------------------------
pulseWidth VAR Word ' Signal sent to servo
toneFreq VAR Word ' Frequency of beeping tone
pulseWidth = 716 ' Found in Ch4 to make 1y circle
toneFreq = 4000 ' Beginning tone is 4 kHz
' -----[ Main Routine ]------------------------------------------------
DO
PULSOUT 13, 850 ' Pulse servos in circular path
PULSOUT 12, pulseWidth ' 12 slower than 13 so it arcs
PAUSE 20
IF (IN5 = 0) THEN ' Left whisker makes circle
IF (pulseWidth <= 845) THEN ' smaller, down to servo max
pulseWidth = puls 5 ' pulseWidth of 850.
toneFreq = to 100
FREQOUT 4, 100, toneFreq ' Play tone as indicator.
ENDIF
ELSEIF (IN7 = 0) THEN ' Right whisker makes circle
IF (pulseWidth >= 655) THEN ' larger, down to servo min
pulseWidth = pulseWidth - 5 ' pulseWidth of 650.
toneFreq = toneFreq - 100
FREQOUT 4, 100, toneFreq ' Play tone as indicator.
ENDIF
ENDIF
LOOP