' © Parallax, Inc. • Application Note AN0001 Faux Candles • 5/2005 ' ========================================================================= ' ' File....... Faux_Candles.BS1 ' Purpose.... Simulate six candles with LEDs; with wind/trigger input ' Author..... Team EFX ' E-mail..... teamefx@parallax.com ' Started.... 19 MAR 2005 ' Updated.... 01 JUN 2005 ' ' {$STAMP BS1} ' {$PBASIC 1.0} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' Simulates candle flicker by passing random values to the "candle" output ' pins (P0 - P5). When TriggerWind is high, the candle appears to burn ' slowly and steadily. When TriggerWind is low, the candle flickers as ' though it was subjected to a stiff breeze. ' -----[ I/O Definitions ]------------------------------------------------- SYMBOL TriggerWind = PIN7 ' active-low (1 -> 0) ' -----[ Constants ]------------------------------------------------------- SYMBOL Yes = 0 ' for active low input SYMBOL No = 1 ' -----[ Variables ]------------------------------------------------------- SYMBOL flicker = W0 ' random flicker SYMBOL blankTest = W1 ' test for extended blank SYMBOL candles = B4 ' new candle outputs SYMBOL flickVal = B5 ' width of darkness SYMBOL flickDly = B6 ' delay between updates ' -----[ Initialization ]-------------------------------------------------- Reset: PINS = %00000000 ' all candles off DIRS = %00111111 ' make LED pins outputs ' -----[ Program Code ]---------------------------------------------------- Main: RANDOM flicker ' tumble random generator IF TriggerWind = Yes THEN Has_Wind No_Wind: flickVal = %0011 ' load calm values flickDly = 12 GOTO Chk_Blackout Has_Wind: flickVal = %1111 ' load windy values flickDly = 45 Chk_Blackout: ' test bits for all zeros blankTest = flicker & flickVal ' isolate test bits IF blankTest > 0 THEN Update_Candles ' if not blank, do update flicker = flicker + 1 ' else insert a 1 Update_Candles: candles = flicker & %00111111 ' use active candle pins PINS = candles ' update LEDs PAUSE flickDly ' delay between updates GOTO Main END