main1: if pin0 = 0 then ; if the line tracker mode is on
high 0 ;turn left motor clockwise
high 3 ;turn right motor clockwise
Right: if pin1 = 1 and pin2 = 1 and pin6 = 0 then ;if tank meets right turn
low 0 ;stop left motor
low 3 ;stop right motor
high 0 ;turn left motor clockwise
high 4 ;turn right motor anticlockwise
loop1: if pin7 = 1 then ;if front sensor meets the line
low 0 ;stop left motor
low 4 ;stop right motor
else
goto loop1 ;keep turning until front sensor hits line
endif
Left: elseif pin1 = 1 and pin6 = 1 and pin2 = 0 then ;if tank meets left turn
low 0 ;stop left motor
low 3 ;stop right motor
high 1 ;turn left motor anticlockwise
high 3 ;turn right motor clockwise
loop2: if pin7 = 1 then ;if center front sensor hits line
low 1 ;stop left motor
low 3 ;stop right motor
else
goto loop2 ;keep turning until front sensor hits line
endif
Offtrack: elseif pin1 = 0 then
OffLeft: if pin2 = 1 then ;if right sensor hits line
low 0 ;stop left motor
low 3 ;stop right motor
high 0 ;turn left motor clockwise
high 4
loop3: if pin7 = 1 then ;turn right motor anticlockwise
low 0
low 4
high 0
high 3
else
goto loop3
endif
loop4: if pin1 = 1 then
low 0
low 3
high 3
high 1
else
goto loop4
endif
loop5: if pin7 = 1 then
low 3
low 1
else
goto loop5
endif
OffRight: elseif pin6 = 1 then
low 0
low 3
high 3
high 1
loop6: if pin7 = 1 then ;turn right motor anticlockwise
low 3
low 1
high 0
high 3
else
goto loop6
endif
loop7: if pin1 = 1 then
low 0
low 3
high 0
high 4
else
goto loop7
endif
loop8: if pin7 = 1 then
low 0
low 4
else
goto loop8
endif
else
goto OffLeft ;keep reversing until center sensor hits line
endif
elseif pin0 = 1 then
goto main2
endif
endif
goto main1
main2: if pin0 = 1 then ; if the signal tracker mode is on
high 0 ;turn left motor clockwise
high 1 ;turn right motor clockwise
RightSig: if pin7 = 1 and pin2 = 1 and pin6 = 0 then ;if tank meets right turn
pause 100
if pin6 = 1 then
goto Failsafe
endif
pause 2000 ;drive until center sensor is at apex
low 0 ;stop left motor
low 3 ;stop right motor
high 0 ;turn left motor clockwise
high 4 ;turn right motor anticlockwise
loop9: if pin7 = 1 then ;if front sensor meets the line
low 0 ;stop left motor
low 4 ;stop right motor
else
goto loop9 ;keep turning until front sensor hits line
endif
LeftSig: elseif pin7 = 1 and pin6 = 1 and pin2 = 0 then ;if tank meets left turn
pause 100
if pin2 = 1 then
goto Failsafe
endif
pause 2000 ;drive until center sensor is at apex
low 0 ;stop left motor
low 3 ;stop right motor
high 1 ;turn left motor anticlockwise
high 3 ;turn right motor clockwise
loop10: if pin7 = 1 then ;if center front sensor hits line
low 1 ;stop left motor
low 3 ;stop right motor
else
goto loop10 ;keep turning until front sensor hits line
endif
StopRev: elseif pin7 = 1 and pin2 = 1 and pin6 = 1 then
Failsafe: low 0 ;stop left motor
low 3 ;stop right motor
high 1 ;turn left motor anticlockwise
high 4 ;turn right motor anticlockwise
pause 2000
loop11: if pin1 = 1 then ;if center sensor hits line
low 1 ;stop left motor
low 4 ;stop right motor
goto Endprogram
else
goto loop11
endif
elseif pin0 = 0 then
goto main1
endif
endif
goto main2
Endprogram: End