' ========================================================================= ' ' File....... Candles-6x.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. ' ' This version als uses a trigger input to simulate wind, and a pot for ' fine-tuning candle flicker. ' -----[ Revision History ]------------------------------------------------ ' -----[ I/O Definitions ]------------------------------------------------- RateCtrl PIN 7 ' RCTIME circuit input Windy PIN 6 ' active-high button Candles VAR OUTL ' candle outputs, P0-P5 ' -----[ Constants ]------------------------------------------------------- Yes CON 1 No CON 0 ' -----[ Variables ]------------------------------------------------------- flicker VAR Word ' random flicker value wicks VAR Byte ' to test for dark rate VAR Word ' 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 Get_Rate: HIGH RateCtrl ' charge cap PAUSE 1 RCTIME RateCtrl, 1, rate ' read speed pot rate = rate */ $0067 MAX 255 ' scale to 0 - 255 Check_Wind: IF (Windy = No) THEN rate = rate / 25 + 5 ' scale to 5 - 15 ELSE rate = rate / 10 + 25 ' scale to 35 - 60 ENDIF Flame_On: Candles = wicks ' update outputs PAUSE rate ' hold flames GOTO Main ' start again ' -----[ Subroutines ]-----------------------------------------------------