' ========================================================================= ' ' File....... Spooky_Eyes.BS2 ' Purpose.... Random "eyes" controller for Halloween haunts ' Author..... Jon Williams -- Parallax, Inc. ' E-mail..... jwilliams@parallax.com ' Started.... ' Updated.... 16 JAN 2005 ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' While triggered, this program will randomly select an set of "eyes" and ' bring them on gradually, hold them on for a moment, then extinguish ' them. The process will complete as long as the trigger is present. ' -----[ Revision History ]------------------------------------------------ ' 15 JAN 2005 - First version; tested on Parallax BS1 Project Board ' -----[ I/O Definitions ]------------------------------------------------- Trigger PIN 7 ' -----[ Constants ]------------------------------------------------------- IsOn CON 0 ' active low input IsOff CON 1 EyePorts CON 7 ' # eye control pins #SELECT $STAMP #CASE BS2, BS2E CycAdj CON $100 ' x 1.0, adjustment (for ms) #CASE BS2SX CycAdj CON $280 ' x 2.5 #CASE BS2P CycAdj CON $188 ' x 1.53 #CASE BS2PE CycAdj CON $09E ' x 0.62 #ENDSELECT RampTm CON 15 ' 15 ms per level ' -----[ Variables ]------------------------------------------------------- randVal VAR Word ' for random # generator eyeNum VAR Nib ' selected eye pin lastNum VAR Nib ' last eye on level VAR Byte ' brighness level ' -----[ Initialization ]-------------------------------------------------- Reset: lastNum = EyePorts - 1 ' calc last control pin FOR eyeNum = 0 TO lastNum ' set used control pins LOW eyeNum ' make output and off NEXT ' -----[ Program Code ]---------------------------------------------------- Main: DO RANDOM randVal ' tumble random generator LOOP WHILE (Trigger = IsOff) ' wait for trigger Get_Eye: eyeNum = randVal // EyePorts ' make 0 to (EyePorts - 1) IF eyeNum = lastNum THEN Main ' do not allow repeat lastNum = eyeNum ' save current selection Show_Eye: FOR level = 0 TO 255 STEP 5 ' increase brightness PWM eyeNum, level, (RampTm */ CycAdj) ' modulate LED eyes NEXT HIGH eyeNum ' full bright PAUSE 500 ' leave on for a bit LOW eyeNum ' selected eye off PAUSE 100 ' inter-eye delay GOTO Main ' start again