'{$STAMP BS2} 'subs.bs2 - Useful subroutnes - Roger Arrick 2/22/03 subs: gosub start gosub panic goto subs freqout 9,150,500 'Beep twice. pause 1000 serout 8,396,["!1M116FFFF"] 'Drive forward forever. pause 1000 gosub backl goto subs 'Start a program with this routine. 'Centers steering, beeps twice, waits for SW1 pressed. ' Start: high 11 'Green LED off. serout 8,396,["!1R180"] 'Steer center. freqout 9,150,2000 'Beep twice. pause 20 freqout 9,150,2000 low 9 'Speaker off. serout 8,396,["!1R100"] 'Relax steering. start1: high 10 'Red LED off. pause 100 if in14=0 then startd 'If SW1 then startd. low 10 'Red LED on. pause 100 goto start1 'Loop. startd: if in14=0 then startd 'Wait till SW1 off. return 'Finished. 'Move the robot back and to the left to avoid an object. ' backl: serout 8,396,["!1M1100001"] 'Drive motor off. pause 300 serout 8,396,["!1R101"] 'Steer right. pause 500 serout 8,396,["!1M1060028"] 'Drive reverse 10". pause 1500 serout 8,396,["!1M1100001"] 'Drive motor off. pause 300 serout 8,396,["!1R180"] 'Steer center. pause 300 return panicv var byte 'Variable for looping. 'Panic - flash the LEDs and sound the alarm. ' panic: for panicv = 1 to 10 'Loop 10 times. low 10 'Red LED on. high 11 'Green LED off. freqout 9,100,1500 'High pitch sound. pause 100 high 10 'Red LED off. low 11 'Green LED on. freqout 9,100,500 'Low pitch sound. pause 100 next 'Loop until done. return 'Done.