'{$STAMP BS2} '{$PBASIC 2.5} ' ************************************************************** ' * Race System Timer/Controller * ' * By Vern Graner SSE, Texas Information Services * ' ************************************************************** ' * Code for BSII to operate an LED "Christmas Tree" to start * ' * the race and position an RC servo controlling the starting * ' * gate * ' ************************************************************** ' *Revision Info: V2.1a (Nic Rocks!) 01-20-2003 * ' * v2.1b Parts List and hookup added * ' ************************************************************** ' Parts: ' BSII stamp microcontroller from Parallax (http://www.parallax.com) ' Standard RC Servo (like futaba 3003, any servo should work) ' Basic Stamp Carrier board (http://www.parallax.com/detail.asp?product_id=27120) ' Push button, n.o. (Normally Open) ' SEETRON serial 2x16 LCD unit (http://www.parallax.com/detail.asp?product_id=27923) ' RED, YELLOW, GREEN LEDs for the tree ' 40ohm speaker (or 8ohm spkr w/10uf cap inline) ' BSII Pins: ' Pin 0 - Servo PWM ' Pin 1 - Button (N.O. to GND through a 1kohm res) ' Pin 10 - RED LED ' Pin 11 - YELLOW LED (one) ' Pin 12 - YELLOW LED (two) ' Pin 13 - GREEN LED ' Pin 14- LCD Serial ' ************************ ' * Variable definitions * ' ************************************************************************* ' ************************ ' * Servo Positions * ' ************************ ServoForward CON 200 ' PWM value to move servo TO "RELEASE" position ServoBack CON 1000 ' PWM value to move servo to "HOLD" position ' ************************ ' * Data Variables * ' ************************ TriggerValue VAR Byte ' sensors results stored here cntI VAR Byte ' For loop variable btnWrk VAR Byte ' Workspace for BUTTON timer VAR Byte ' elapsed time of race ' ************************ ' * LCD variables * ' ************************ N9600 CON $4054 ' Baudmode-9600 bps inverted. Use $40F0 for BS2-SX. I CON 254 ' Instruction prefix value. CLR CON 1 ' LCD clear-screen instruction. LINE2 CON 192 ' Address of 1st char of 2nd line. ' ************************ ' * Display Version Info * ' ************************ PAUSE 1000 SEROUT 14,n9600,[I,CLR] SEROUT 14,n9600,["Pinewood Rocks!"] SEROUT 14,n9600,[I,LINE2] SEROUT 14,n9600,["V2.1a (c)VGraner"] HIGH 13 waitbut0: TOGGLE 13 PAUSE 150 BUTTON 1, 1, 255, 250, btnWrk, 0, waitbut0 LOW 13 ' ************************ ' * Main Code * ' ************************************************************************* Main: ' ************************ ' * Display Instructions * ' ************************ SEROUT 14,n9600,[I,CLR] SEROUT 14,n9600,["Stage Racers,"] SEROUT 14,n9600,[I,LINE2] SEROUT 14,n9600,["then Hit START!"] ' ************************* ' * Wait for START button * ' ************************* waitbut1: PULSOUT 0,ServoForward PAUSE 20 BUTTON 1, 1, 255, 250, btnWrk, 0, waitbut1 ' ************************* ' * Do the Tree countdown * ' ************************* GOSUB TREEON ' ************************ ' * Display Gate State * ' ************************ SEROUT 14,n9600,[I,CLR] SEROUT 14,n9600,["Manually close"] SEROUT 14,n9600,[I,LINE2] SEROUT 14,n9600,["gate, hit START."] ' ************************* ' * Wait for button * ' ************************* BLINKY: BUTTON 1, 1, 255, 250, btnWrk, 1, waitbut2 HIGH 13 PAUSE 60 LOW 13 BUTTON 1, 1, 255, 250, btnWrk, 1, waitbut2 HIGH 12 PAUSE 60 LOW 12 BUTTON 1, 1, 255, 250, btnWrk, 1, waitbut2 HIGH 11 PAUSE 60 LOW 11 BUTTON 1, 1, 255, 250, btnWrk, 1, waitbut2 HIGH 10 PAUSE 60 LOW 10 BUTTON 1, 1, 255, 250, btnWrk, 1, waitbut2 GOTO BLINKY waitbut2: ' ************************ ' * Display Gate State * ' ************************ SEROUT 14,n9600,[I,CLR] SEROUT 14,n9600,["Closing Latch..."] GOSUB TREEOFF GOSUB CloseGate ' ************************ ' * Display Gate State * ' ************************ SEROUT 14,n9600,[I,CLR] SEROUT 14,n9600,["Latch Closed."] SEROUT 14,n9600,[I,LINE2] SEROUT 14,n9600,["Ready to Race!"] PAUSE 2000 GOTO MAIN ' ************************ ' * Subroutines Section * ' ************************************************************************* ' ************************** ' * Servo to "latched" state ' ************************** CloseGate: FOR cntI=1 TO 40 PULSOUT 0,ServoForward PAUSE 20 NEXT FREQOUT 9, 100, 1200 FREQOUT 9, 75, 1600 RETURN ' ************************** ' * Turn off tree lights * ' ************************** TreeOff: LOW 13 LOW 12 LOW 11 LOW 10 RETURN ' ************************** ' * Tree Countdown * ' ************************** TreeOn: SEROUT 14,n9600,[I,CLR] SEROUT 14,n9600,[">> <<"] ' SEROUT 14,n9600,[I,LINE2] HIGH 13 FREQOUT 9, 250, 2000 PAUSE 500 SEROUT 14,n9600,[I,CLR] SEROUT 14,n9600,["==>> <<=="] LOW 13 HIGH 12 FREQOUT 9, 250, 2000 PAUSE 500 SEROUT 14,n9600,[I,CLR] SEROUT 14,n9600,[" -==>> <<==- "] LOW 12 HIGH 11 FREQOUT 9, 250, 2000 PAUSE 500 SEROUT 14,n9600,[I,CLR] SEROUT 14,n9600,[" -==>>!GO!<<==- "] LOW 11 HIGH 10 FOR cntI=1 TO 100 PULSOUT 0,ServoBack FREQOUT 9, 20, 2500,2000 TOGGLE 10 NEXT RETURN