Chapter 5: Basic Competition Code · Page 49
GOTO Main
Scan_Left: ' spin left, slow
FOR pulses = 1 TO 5
PULSOUT LMotor, LRevSlow
PULSOUT RMotor, RFwdSlow
PAUSE 20
NEXT
GOSUB Creep_Forward
GOTO Main
Follow_Right: ' spin right, fast
PULSOUT LMotor, LFwdFast
PULSOUT RMotor, RRevSlow
lastIR = irBits ' save last direction found
GOTO Main
Follow_Left: ' spin left, fast
PULSOUT LMotor, LRevSlow
PULSOUT RMotor, RFwdFast
lastIR = irBits
GOTO Main
Lunge: ' locked on -- go get him!
FOR pulses = 1 TO 25
PULSOUT LMotor, LFwdFast
PULSOUT RMotor, RFwdFast
GOSUB Read_Line_Sensors
IF (lineBits = %11) THEN Match_Over ' in sight, we're on the line
NEXT
GOTO Main
' If SumoBot can see the opponent with both "eyes" and both QTIs are
' detecting the border, we must have pushed the opponent out.
Match_Over:
FOR pulses = 1 TO 10 ' stop motors
PULSOUT LMotor, LStop
PULSOUT RMotor, RStop
PAUSE 20
NEXT
INPUT LMotor
INPUT RMotor
FOR temp = 1 TO 10 ' make some noise
HIGH StartLED
FREQOUT Speaker, 100, 2500, 3000 ' beep
INPUT StartLED ' blink LED
PAUSE 100
NEXT