'{$STAMP BS2} '{$PBASIC 2.5} ' ************************************************************** ' * Spider Slammer routine using the Rogue Robotics uMP3 * ' * By Vern Graner SSE, Texas Information Services * ' ************************************************************** ' * Code operates a pneumatic cylinder and the uMP3 * ' ************************************************************** ' * Revision Info: V1.0 (VLG) 10-24-2005 * ' * Update 10-28-2005 v1.5 (VLG) * ' ************************************************************** ' ************************ ' * Idea cache * ' ************************************************************** ' Backlight the tank to show spiders behind when striking slammer ' front light the tank w/the fading LEDs so eggs throb and background is ' invisible? ' ************************************************************** ' ************************ ' * I/O Definitions * ' ************************************************************************* 'Slammer pins: RC4 PIN 0 ' RC4 Relay Channel ' avail PIN 1 ' ' avail PIN 2 ' MP3T PIN 4 ' uMP3: set the pin where the uMP3 "T" pin is connected MP3R PIN 5 ' uMP3: set the pin where the uMP3 "R" pin is connected Water PIN 11 ' Water Pump for venom squirter TrigLED PIN 7 ' LED on button (Green) Fog PIN 8 ' Fog Machine Slammer PIN 13 ' Solenoid Valve FOr Spider Slammer (red) LCD PIN 14 ' Serial LCD panel TRIGGER PIN 15 ' N.O. Momentary Push Button on PIN3 ' TRIGGER PIN 1 ' N.O. Momentary Push Button on PIN3 ' ************************ ' * Constant definitions * ' ************************************************************************* ' RC4A Strobe CON 1 ' Strobe for strike (Yellow 1) Chamber CON 2 ' Chamber light (Yellow 2) DoorRope CON 3 ' Doorway Outline Rope Lights BlackLight CON 4 ' Overhead Black Light Fixture ' RC4B BackLight CON 4 ' Tank Backlight Beacon CON 3 ' Rotating Beacon TRUE CON 1 ' use for binary operations FALSE CON 0 ' ibid N9600T CON 84 ' uMP3: Set the 9600 8 bit no parity TRUE N9600 CON $4054 ' LCD Baudmode-9600 bps inverted. Use $40F0 for BS2-SX. I CON 254 ' LCD Instruction prefix value. CLR CON 1 ' LCD clear-screen instruction. LINE2 CON 192 ' LCD Address of 1st char of 2nd line. TOP CON 2 ' LCD CRSR to home position RC4A CON %00 ' RC4A %00 - %11 RC4B CON %01 ' RC4B %00 - %11 BAUD CON 396 ' RC4 Baud for RC-4 ' ************************ ' * 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 cntX 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 * ' ************************************************************************* ' TEST1: ' LOW WATER ' IF TRIGGER = true THEN TEST1 ' HIGH WATER ' GOTO test1 ' ************************ ' * Display Version Info * ' ************************************************************************* SEROUT LCD,n9600,[I,CLR] SEROUT LCD,n9600,[" Spider Slammer "] SEROUT LCD,n9600,[I,LINE2] SEROUT LCD,n9600,["V1.0 (c)VGraner"] ' PAUSE 1000 ' ************************* ' * INIT uMP3 unit * ' ************************* SEROUT LCD,n9600,[I,CLR] SEROUT LCD,n9600,["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 MAIN: ' ************************* ' * Wait for Trigger * ' ************************* GOSUB uStop ' Turn ON the room Black Light SEROUT RC4, Baud, ["!RC4", RC4A, "R", BlackLight, TRUE] LOW TrigLED SEROUT LCD,n9600,[I,CLR] SEROUT LCD,n9600,["Waiting:"] SEROUT LCD,n9600,[I,LINE2] SEROUT LCD,n9600,["Trigger"] Lottery = 1130 'seed value to gets things going LoopPoint: FOR cntI = 0 TO 255 Lottery=Lottery+3 ' take the current value for a seed when button pressed IF TRIGGER = FALSE THEN DIALOG ' IF TRIGGER = TRUE THEN DIALOG NEXT TOGGLE TrigLED GOTO LOOPPOINT ' ************************* ' * Start the dialog * ' ************************* Dialog: 'GOTO Slam LOW TrigLED SEROUT LCD,n9600,[I,CLR] SEROUT LCD,n9600,["Playing:"] SEROUT LCD,n9600,[I,LINE2] SEROUT LCD,n9600,["Kiosk Dialog"] 'Turn on the Chamberlight SEROUT RC4, Baud, ["!RC4", RC4A, "R", CHAMBER, TRUE] SEROUT MP3R,N9600T,["PC F /kiosk9.mp3",CR] 'Play the dialog ' how long b4 the spider jumps? ' The speech is currently 39 seconds long HIGH FOG PAUSE 2500 LOW FOG 'Wiggle the eggs with a servo FOR cntI=1 TO 6 ' adjust from 2 to 20 for timing RANDOM Lottery ServoPosition=Lottery // 800 + 100 FOR ServoLoop=1 TO 30 PULSOUT 1,ServoPosition PAUSE 20 NEXT NEXT HIGH FOG PAUSE 2500 LOW FOG 'Wiggle the eggs with a servo FOR cntI=1 TO 6 ' adjust from 2 to 20 for timing RANDOM Lottery ServoPosition=Lottery // 800 + 150 FOR ServoLoop=1 TO 30 PULSOUT 1,ServoPosition PAUSE 20 NEXT NEXT '******************************************************************************** ' Spider Slam Sequence Begin '******************************************************************************** Slam: SEROUT LCD,n9600,[I,CLR] SEROUT LCD,n9600,["Playing:"] SEROUT LCD,n9600,[I,LINE2] SEROUT LCD,n9600,["Spider Scream"] ' Play the spider scream SEROUT MP3R,N9600T,["PC F /spider-scream3.mp3",CR] 'Play the spider noise ' Turn OFF the Overhead Blacklight SEROUT RC4, Baud, ["!RC4", RC4A, "R", BlackLight, FALSE] ' Turn OFF the Chamber light SEROUT RC4, Baud, ["!RC4", RC4A, "R", Chamber, FALSE] 'Turn on the BACKlight SEROUT RC4, Baud, ["!RC4", RC4B, "R", BACKlight, TRUE] 'Turn on the strobe light SEROUT RC4, Baud, ["!RC4", RC4A, "R", Strobe, TRUE] ' Notes: ' If, For example, you want Crate 1 To shake every 15 To 30 seconds ' you would change the timer line To this: ' timer1 = lottery // 16 + 15 ' The first number (after //) is the span between the MIN AND MAX times, plus 1. ' The second number (after +) is the minimum timer value. so: ' result = lottery // SPAN + MINIMUM 'Slam the spider! 'FOR cntI = 1 TO 32 ' IF cntI < 3 THEN 'Squirt water for the first 10 cycles ' HIGH Water 'Squirt Water ' ELSE ' LOW Water 'Stop Water ' ENDIF ' GOSUB Blackout 'Test3: 'IF TRIGGER = FALSE THEN HIGH Slammer 'IF TRIGGER = TRUE THEN LOW Slammer 'GOTO Test3 HIGH Slammer PAUSE 750 LOW Slammer PAUSE 350 HIGH Slammer PAUSE 600 LOW Slammer PAUSE 250 HIGH Slammer PAUSE 700 LOW Slammer PAUSE 450 HIGH Slammer PAUSE 750 LOW Slammer PAUSE 350 HIGH Slammer PAUSE 800 LOW Slammer PAUSE 250 ' RANDOM Lottery ' SlamDwell=Lottery // 16 + 15 ' HIGH Slammer 'Move spider into view ' DEBUG "On Dwell=",DEC SlamDwell,CR ' PAUSE SlamDwell ' RANDOM Lottery ' SlamDwell=Lottery // 30 + 100 ' LOW Slammer 'Retract spider from view ' PAUSE SlamDwell 'NEXT 'Retract spider LOW SLAMMER ' Turn OFF the strobe SEROUT RC4, Baud, ["!RC4", RC4A, "R", Strobe, False] GOSUB Blackout 'PAUSE 5000 ' SEROUT LCD,n9600,[I,CLR] ' SEROUT LCD,n9600,["Playing:"] ' SEROUT LCD,n9600,[I,LINE2] ' SEROUT LCD,n9600,["Toxin Warning"] ' Play the emergency alert PAUSE 20 SEROUT MP3R,N9600T,["PC F /Toxin-Warning-1-min.mp3",CR] 'Play the spider noise PAUSE 20 SEROUT MP3R,N9600T,["PC F /Toxin-Warning-1-min.mp3",CR] 'try again in case it misses! WTF?!? 'Turn on the Rotating Beacon SEROUT RC4, Baud, ["!RC4", RC4B, "R", Beacon, TRUE] FOR cntI = 1 TO 100 IF TRIGGER = FALSE THEN ManualReset SEROUT RC4, Baud, ["!RC4", RC4A, "R", DoorRope, True] PAUSE 100 IF TRIGGER = FALSE THEN ManualReset SEROUT RC4, Baud, ["!RC4", RC4A, "R", DoorRope, False] PAUSE 100 NEXT ManualReset: 'Turn OFF the Rotating Beacon SEROUT RC4, Baud, ["!RC4", RC4B, "R", Beacon, False] 'Turn OFF the Doorway Rope Light SEROUT RC4, Baud, ["!RC4", RC4A, "R", DoorRope, False] PAUSE 1000 ' make sure we wait for the button to be released GOTO MAIN ' ************************ ' * Subroutines * ' ************************************************************************* uStop: 'Stop the player ' DEBUG "PC S"," ",CR ' SEROUT LCD,n9600,[I,CLR] ' SEROUT LCD,n9600,["Player Command: "] SEROUT LCD,n9600,[I,LINE2] SEROUT LCD,n9600,[" STOP "] SEROUT MP3R,N9600T,["PC S",CR] GOSUB READMP3 PAUSE 500 RETURN uPause: 'Toggle player pause SEROUT LCD,n9600,[I,LINE2] SEROUT LCD,n9600,["PAUSE TOGGLE "] ' DEBUG "PC P"," ",CR SEROUT MP3R,N9600T,["PC P",CR] GOSUB READMP3 PAUSE 500 RETURN uVolReset: 'Reset the volume to "full" VOLUME=0 SEROUT LCD,n9600,[I,LINE2] SEROUT LCD,n9600,[" Volume-FULL "] ' DEBUG "ST V",DEC VOLUME," ",CR SEROUT MP3R,N9600T,["ST V ",DEC Volume,CR] GOSUB READMP3 PAUSE 500 RETURN uWaitDone: ' Wait here till the current song finishes ' DEBUG "Waiting for Song End...",CR SEROUT LCD,n9600,[I,LINE2] SEROUT LCD,n9600,["Waiting-End "] PAUSE 250 WAITING: SEROUT MP3R,N9600T,["PC Z",CR] ' Check the status of the uMP3 SERIN MP3T, N9600T, 1000, noData1, [serdata] ' Get the response ' DEBUG serdata,CR ' Debug to see what the uMP3 is returning IF serdata = "S" THEN RETURN ' If the player has finished playing the file, jump to the start noData1: PAUSE 100 ' Wait a bit so we don't flood the uMP3 with serial commands GOTO WAITING ' Loop back to wiating point ReadMP3: 'Read command response from uMP3 unit SERIN MP3T, N9600T, 2000, No_Resp1, [serdata] SEROUT LCD,n9600,[I,LINE2] SEROUT LCD,n9600,[serdata] RETURN No_Resp1: 'Tell user there is no reply from uMP3 SEROUT LCD,n9600,[I,LINE2] SEROUT LCD,n9600,["Com Er: Timeout"] RETURN Blackout: SEROUT LCD,n9600,[I,LINE2] SEROUT LCD,n9600,["Blackout"] LOW Water LOW Fog LOW Slammer LOW TrigLED SEROUT RC4, Baud, ["!RC4", rc4A, "X"] ' all off SEROUT RC4, Baud, ["!RC4", rc4B, "X"] ' all off RETURN