' ========================================================================= ' ' File....... LIGHTS_ON.BS1 ' Purpose.... Lights/Door controller for airport ' Author..... Jon Williams -- Parallax, Inc. ' E-mail..... jwilliams@parallax.com ' Started.... 10 JUL 1994 ' Updated.... 10 SEP 2005 ' ' {$STAMP BS1} ' {$PBASIC 1.0} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' The program idles until recieving a microphone "click" on which it con- ' tinues to monitor the input for about 10 seconds. If at least 6 clicks ' were recieved then the Lights output in enabled. If at least 8 clicks ' were recieved then the Doors output is also enabled. The final output ' section is designed so that the Lights and Doors can be timed indepen- ' dently. ' ' Note: One-shot reset is high blip. ' Control outputs are active low (sink). ' -----[ Revision History ]------------------------------------------------ ' ' 07-10-94... Version 1.0 ' 07-11-94... Fine tuned timing loop constants ' 09-10-05... Reformatted to current standards (Elements of PBASIC Style) ' -----[ I/O Definitions ]------------------------------------------------- SYMBOL ClixIn = 0 ' mic click (in) SYMBOL OsRst = 1 ' one-shot reset (out) SYMBOL Lights = 6 ' light control (out) SYMBOL Doors = 7 ' door control (out) ' -----[ Constants ]------------------------------------------------------- SYMBOL TimerDelay = 755 ' tuned for 10 seconds SYMBOL LightClix = 6 ' 6 clicks for lights SYMBOL DoorClix = 8 ' 8 clicks for doors SYMBOL LightOn = 912 ' tuned for 15 min SYMBOL DoorOn = 304 ' tuned for 5 min ' -----[ Variables ]------------------------------------------------------- SYMBOL numClix = B0 ' clicks counter SYMBOL work = B1 ' button workspace SYMBOL timer = W1 ' time delay counter SYMBOL tmrDelay = W2 ' output length ' -----[ EEPROM Data ]----------------------------------------------------- ' -----[ Initialization ]-------------------------------------------------- Reset: DIRS = %11000010 ' port setup PINS = %11000000 ' outputs off ' -----[ Program Code ]---------------------------------------------------- Main: work = 0 ' clear button workspace BUTTON ClixIn, 0, 255, 0, work, 0, Main ' wait for input PULSOUT OsRst, 100 ' reset one-shot numClix = 1 ' count first click timer = 0 ' reset timer Monitor: BUTTON ClixIn, 0, 255, 0, work, 0, Inc_T0 ' check input PULSOUT OsRst, 100 ' reset one-shot numClix = numClix + 1 ' update click count Inc_T0: PAUSE 10 ' 10 ms delay timer = timer + 1 ' update timer IF timer = TimerDelay THEN Check_Clix ' if timer done, check IF numClix = DoorClix THEN Check_Clix ' early exit GOTO Monitor ' timer still active Check_Clix: IF numClix < LightClix THEN Main ' not enough... LOW Lights ' lights on IF numClix < DoorClix THEN Do_Timer1 ' doors too? LOW Doors ' open sesame! Do_Timer1: timer = 0 ' reset timer tmrDelay = LightOn ' set output length IF tmrDelay > DoorOn THEN Timer_1A ' find longest time tmrDelay = DoorOn ' door time longer Timer_1A: PAUSE 1000 ' 1 second delay timer = timer + 1 ' update timer IF timer < LightOn THEN Timer_1B ' check lights delay HIGH Lights ' lights off Timer_1B: IF timer < DoorOn THEN Timer_1C ' check doors delay HIGH Doors ' close sesame... Timer_1C: IF timer = tmrDelay THEN Main ' timer done, restart GOTO Timer_1A ' keep timing ' -----[ Subroutines ]-----------------------------------------------------