' ========================================================================= ' ' File....... Candles.BS2 ' Purpose.... Light faux candles (with LED wicks) ' Author..... Parallax Team EFX ' E-mail..... teamefx@parallax.com ' Started.... ' Updated.... 28 SEP 2005 ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' This program controls six faux candles. Each candle "flame" is comprised ' of three LEDs, a resistor, and a capacitor. The capacitor allows the ' flame to fade when the BASIC Stamp output goes off, creating a more ' realistic effect. ' -----[ Revision History ]------------------------------------------------ ' -----[ I/O Definitions ]------------------------------------------------- Candles VAR OUTL ' candle outputs, P0-P5 ' -----[ Constants ]------------------------------------------------------- FlickBase CON 10 ' flicker base timing ' -----[ Variables ]------------------------------------------------------- flicker VAR Word ' random flicker value flickVar VAR flicker.BYTE1 ' affects flicker rate wicks VAR Byte ' to test for dark rate VAR Byte ' flicker rate ' -----[ EEPROM Data ]----------------------------------------------------- ' -----[ Initialization ]-------------------------------------------------- Reset: DIRL = %00111111 ' make P0 - P5 outputs ' -----[ Program Code ]---------------------------------------------------- Main: RANDOM flicker ' tumble random generator Check_Dark: wicks = flicker & %00111111 ' test value IF wicks = %000000 THEN Main ' if dark, try again Flame_On: Candles = wicks ' update outputs rate = flickVar & %00001111 + FlickBase ' isolate lower 4 bits PAUSE rate ' hold flames GOTO Main ' start again ' -----[ Subroutines ]-----------------------------------------------------