' ========================================================================= ' ' File....... Spooky_Eyes.BS1 ' Purpose.... Random "eyes" controller for Halloween haunts ' Author..... Jon Williams -- Parallax, Inc. ' E-mail..... jwilliams@parallax.com ' Started.... ' Updated.... 16 JAN 2005 ' ' {$STAMP BS1} ' {$PBASIC 1.0} ' ' ========================================================================= ' -----[ 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 ]------------------------------------------------- SYMBOL Trigger = PIN7 ' -----[ Constants ]------------------------------------------------------- SYMBOL IsOn = 0 ' active low input SYMBOL IsOff = 1 SYMBOL EyePorts = 7 ' # eye control pins ' -----[ Variables ]------------------------------------------------------- SYMBOL randVal = W1 ' for random # generator SYMBOL eyeNum = B4 ' selected eye pin SYMBOL lastNum = B5 ' last eye on SYMBOL level = B6 ' 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: RANDOM randVal ' tumble random generator IF Trigger = IsOff THEN Main ' 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, 3 ' 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