'ZX-LineTracker example for izeBOT of Robo-Stamp2SX ' {$STAMP BS2sx} ' {$PBASIC 2.5} C VAR Bit L VAR Bit R VAR Bit X VAR Bit B VAR Byte B=0 GOSUB Wait_KEY DIRD = $F ' Motor control pin set to output GOSUB FD : PAUSE 600 DO WHILE (B<10) L=IN0 R=IN1 X=IN3 IF(X=0) THEN B=B+1 SEROUT 6,240,[DEC B] IF((B=2) OR (B=5) OR (B=8) OR (B=9)) THEN GOSUB R90 ELSEIF (B=3) THEN IF ((L=0) AND (R=0)) THEN B=B+1 GOSUB FD : PAUSE 400 ELSEIF ((L=1) AND (R=0)) THEN GOSUB FD : PAUSE 100 DO WHILE (IN2=1) GOSUB SR LOOP B=B-1 ELSEIF ((L=0) AND (R=1)) THEN GOSUB FD :PAUSE 100 DO WHILE (IN2=1) GOSUB SL LOOP B=B-1 ENDIF ELSEIF (B=4) THEN GOSUB FD :PAUSE 300 ELSEIF (B=7) THEN GOSUB BUMP ELSE GOSUB L90 ENDIF ENDIF IF((L=1) AND (R=1)) THEN GOSUB FD ELSEIF (L=0) THEN DO WHILE (IN2=1) : GOSUB SL : LOOP ELSEIF (R=0) THEN DO WHILE (IN2=1) : GOSUB SR : LOOP ENDIF LOOP GOSUB FD : PAUSE 1600 GOSUB AO END Wait_KEY: DO : LOOP UNTIL (IN4 = 0) : RETURN until keypress to start BUMP : GOSUB FD : PAUSE 800 DO WHILE (IN3=1): GOSUB FD :LOOP
' Wait
DO WHILE (IN3=0):GOSUB FD : LOOP GOSUB BK :PAUSE 1500 DO WHILE (IN3=1):GOSUB BK : LOOP GOSUB BK :PAUSE 600 DO WHILE (IN3=1):GOSUB BK : LOOP GOSUB FD : PAUSE 600 GOSUB SR : PAUSE 300 DO WHILE (IN2=1) : GOSUB SR : LOOP RETURN R90 : GOSUB FD : PAUSE 600 GOSUB SR : PAUSE 300 DO WHILE (IN2=1) : GOSUB SR : LOOP RETURN L90 : GOSUB FD : PAUSE 600 GOSUB SL : PAUSE 300 DO WHILE (IN2=1) : GOSUB SL : LOOP :PAUSE 40 RETURN '+++++ Movement Procedure +++++++++++++++++++++++++++++ FD: OUTD = %1010 : RETURN ' Motor A --> and Motor B --> Go Forward BK: OUTD = %0101 : RETURN ' Motor A <-- and Motor B <-Go Backward SL: OUTD = %0110 : RETURN ' Robot Spin Left SR: OUTD = %1001 : RETURN ' Robot Spin Right AO: OUTD = 0 : RETURN ' Stop All Motor '++++++++++++++++++++++++++++++++++++++++++++++++++++++