'{$STAMP BS2} '{$PBASIC 2.5} ' ************************************************************** ' * Giant Spider routine using the Rogue Robotics uMP3 * ' * By Vern Graner SSE, Texas Information Services * ' ************************************************************** ' * Code operates a pneumatic cylinder and the uMP3 * ' * and some 110vac lights ' ************************************************************** ' * Update 10-30-2005 v1.0 (VLG) * ' * Update 10-31-2005 7:05pm !!!! :) * ' ************************************************************** ' ************************ ' * I/O Definitions * ' ************************************************************************* 'Slammer pins: SERVO PIN 0 ' servo header 1 LCD PIN 1 ' servo header 2 ' avail PIN 2 ' servo header 3 ' avail PIN 3 ' servo header 4 ' BlackLight PIN 4 ' ULN2803a-1 ' avail PIN 5 ' ULN2803a-1 ' avail PIN 6 ' ULN2803a-1 ' avail PIN 7 ' ULN2803a-1 ' avail PIN 8 ' ULN2803a-1 ' avail PIN 9 ' ' avail PIN 10 ' ' avail PIN 11 ' MP3T PIN 12 ' uMP3: set the pin where the uMP3 "T" pin is connected MP3R PIN 13 ' uMP3: set the pin where the uMP3 "R" pin is connected TRIGGER PIN 14 ' N.O. Momentary Push Button on PIN3 ' avail PIN 15 ' Serial LCD panel ' ************************ ' * Constant definitions * ' ************************************************************************* BlackLight CON 4 ' Overhead Black Light Fixture Strobe CON 5 ' Strobe for attack Spider CON 6 ' Pneumatic for spider jump TRUE CON 1 ' use for binary operations FALSE CON 0 ' ibid N9600T CON 84 ' uMP3: Set the 9600 8 bit no parity TRUE CurtainHold CON 220 ' PWM value to move servo TO "RELEASE" position CurtainDrop CON 1050 ' PWM value to move servo to "HOLD" position GuidePause CON 10 ' How Long between "trigger" and "attack of the spider" N9600 CON $4054 ' Baudmode-9600 bps inverted. Use $40F0 for BS2-SX. LcdBaud CON 32 ' 19.2k baud (BS2 @ rates) LcdLF CON $0A ' move cursor down 1 line LcdCls CON $0C ' clear LCD (use PAUSE 5 after) LcdCR CON $0D ' move pos 0 of next line LcdBLon CON $11 ' backlight on LcdBLoff CON $12 ' backlight off LcdOff CON $15 ' LCD off LcdOn1 CON $16 ' LCD on; cursor off, blink off LcdLine1 CON $80 ' move to line 1, column 0 LcdLine2 CON $94 ' move to line 2, column 0 ' ************************ ' * Variables * ' ************************************************************************* serdata VAR Byte ' For response from the uMP3 btnWrk VAR Byte ' Workspace for BUTTON Volume VAR Byte ' Volume control variable 0-255, 0= loudest TriggerValue VAR Byte ' sensors results stored here cntI VAR Byte ' general counter variable 0-255 Lottery VAR Word ' For Random Number generator SlamDwell VAR Byte ' Random number for slammer dwell time ServoLoop VAR Byte ServoPosition VAR Word ' ************************ ' * Main Program Begin * ' ************************************************************************* ' ************************ ' * Display Version Info * ' ************************************************************************* PAUSE 250 ' Wait for the LCD to INIT SEROUT LCD, LcdBaud, [LcdOn1, LcdCls, LcdBLon] 'init LCD SEROUT LCD, LCDBaud, [" Giant Spider "] SEROUT LCD, LCDBaud, [LcdLine2] SEROUT LCD, LCDBaud, ["V1.0 (c)VGraner"] PAUSE 1000 ' ************************* ' * INIT uMP3 unit * ' ************************* SEROUT LCD,lcdBaud,[LcdCls] SEROUT LCD,LcdBaud,["Initializing... "] SEROUT MP3R,N9600T,[CR] 'Send an INIT CR to the uMP3 GOSUB ReadMP3 'Check for response from uMP3 PAUSE 250 GOSUB BLACKOUT 'Turn Everything off! PAUSE 250 GOSUB USTOP 'Tell the unit to STOP in case it's playing PAUSE 250 GOSUB uVolReset 'Reset the uMP3 volume to FULL PAUSE 250 FOR cntI=1 TO 30 'Set the curtain Hook PULSOUT 0,CurtainHold PAUSE 20 NEXT HIGH Spider HIGH BLACKLIGHT 'GOTO test6 ' REMOVE BEFORE FINAL!!!! MAIN: ' ************************* ' * Wait for Trigger * ' ************************* GOSUB uStop HIGH BlackLight' Turn ON the room Black Light LOW STROBE ' Turn Off The Strobe and backlights GOSUB uVolHalf ' set the uMP3 to half volume for ambience SEROUT MP3R,N9600T,["PC O 0",CR] 'set continuous loop mode SEROUT MP3R,N9600T,["PC F /SpaceTek.mp3",CR] 'Play the ambience SEROUT LCD, LcdBaud, [LcdOn1, LcdCls, LcdBLon] 'init LCD SEROUT LCD, LCDBaud, ["Task-Playing "] SEROUT LCD, LCDBaud, [LcdLine2] SEROUT LCD, LCDBaud, ["Tek Ambience "] 'SEROUT LCD, LcdBaud, [LcdBLon] 'turn on the LCD backlight LoopPoint: IF TRIGGER = TRUE THEN LOOPPOINT ' wait for the trigger button '******************************************************************************** ' Spider Attack Sequence Begin '******************************************************************************** 'SEROUT LCD, LcdBaud, [LcdBLoff] 'turn off LCD backlight SEROUT MP3R,N9600T,["PC O 1",CR] 'set "Play Once" mode SEROUT LCD, LcdBaud, [LcdCls] SEROUT LCD, LCDBaud, ["Task-Countdown "] FOR cntI = GuidePause TO 1 SEROUT LCD, LCDBaud, [LcdLine2] SEROUT LCD, LCDBaud, ["Attack in:", DEC cntI," "] PAUSE 1000 NEXT SEROUT MP3R,N9600T,["PC F /SpiderAttack-Clean.mp3",CR] 'Play the sound effects GOSUB uVolReset 'Reset the uMP3 volume to FULL SEROUT LCD, LcdBaud, [LcdOn1, LcdCls] SEROUT LCD, LCDBaud, ["Task- "] SEROUT LCD, LCDBaud, [LcdLine2] SEROUT LCD, LCDBaud, ["Attacking! "] PAUSE 500 LOW BlackLight FOR cntI=1 TO 30 PULSOUT 0,CurtainDrop PAUSE 20 NEXT 'PAUSE 250 test6: HIGH Strobe FOR cntI = 1 TO 4 ' Bounce the spider! LOW Spider PAUSE 750 HIGH Spider PAUSE 650 LOW Spider PAUSE 350 HIGH Spider PAUSE 845 LOW Spider PAUSE 450 HIGH Spider PAUSE 750 NEXT HIGH SPIDER 'return to upright SEROUT LCD, LcdBaud, [LcdOn1, LcdCls] 'init LCD SEROUT LCD, LCDBaud, ["Task- "] SEROUT LCD, LCDBaud, [LcdLine2] SEROUT LCD, LCDBaud, ["Reseting "] HIGH Blacklight LOW Strobe FOR cntI=1 TO 60 'Reset the curtain holder PULSOUT 0,CurtainHold PAUSE 20 NEXT GOTO MAIN ' ************************ ' * Subroutines * ' ************************************************************************* uStop: 'Stop the player ' DEBUG "PC S"," ",CR SEROUT LCD,LcdBaud,[LcdCls] SEROUT LCD,LcdBaud,["Player Command: "] SEROUT LCD,LcdBaud,[LcdLine2] SEROUT LCD,LcdBaud,[" STOP "] SEROUT MP3R,N9600T,["PC S",CR] GOSUB READMP3 PAUSE 500 RETURN uPause: 'Toggle player pause SEROUT LCD,LcdBaud,[LcdLIne2] SEROUT LCD,LcdBaud,["PAUSE TOGGLE "] SEROUT MP3R,N9600T,["PC P",CR] GOSUB READMP3 PAUSE 500 'RETURN uVolReset: 'Reset the volume to "full" VOLUME=0 SEROUT LCD,LcdBaud,[LcdLIne2] SEROUT LCD,LcdBaud,[" Volume-FULL "] ' DEBUG "ST V",DEC VOLUME," ",CR SEROUT MP3R,N9600T,["ST V ",DEC Volume,CR] GOSUB READMP3 PAUSE 500 RETURN uVolHalf: 'Reset the volume to "half" VOLUME=20 SEROUT LCD,LcdBaud,[LcdLIne2] SEROUT LCD,LcdBaud,[" Volume-Half "] ' DEBUG "ST V",DEC VOLUME," ",CR SEROUT MP3R,N9600T,["ST V ",DEC Volume,CR] GOSUB READMP3 PAUSE 500 RETURN ReadMP3: 'Read command response from uMP3 unit SERIN MP3T, N9600T, 2000, No_Resp1, [serdata] SEROUT LCD,LcdBaud,[LcdLIne2] SEROUT LCD,LcdBaud,[serdata] RETURN No_Resp1: 'Tell user there is no reply from uMP3 SEROUT LCD,LcdBaud,[LcdLIne2] SEROUT LCD,LcdBaud,["Com Er: Timeout"] RETURN Blackout: SEROUT LCD,LcdBaud,[LcdLine2] SEROUT LCD,LcdBaud,["Blackout"] ' SEROUT RC4, Baud, ["!RC4", rc4A, "X"] ' all off ' SEROUT RC4, Baud, ["!RC4", rc4B, "X"] ' all off RETURN