November 22, 2024, 08:47:59 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


new Candle effect

Started by imagineerdan, February 10, 2009, 02:12:30 PM

Previous topic - Next topic

imagineerdan

I was wondering how the coding would look to insert blackout pauses for the Candle_flicker code? So the code would be modified that only pin3 and pin4 would flicker, and that there would be an adjustible pause time variable so both pins would be blacked out?

JonnyMac

Controlling individual wicks is easy with a mask written to the DIRS register (a 0 bit will disable an output).  Do you have program that you're wanting updated? -- I can't find a program called Candle_Flicker on my system.
Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

Ohh you are correct that would help! Its just the code you wrote titled Faux_candles.bs1

JonnyMac

February 10, 2009, 03:44:01 PM #3 Last Edit: February 10, 2009, 03:47:49 PM by JonnyMac
Here's an example of individual wick control (with timing) using a mask value that is written to the DIRS register.  We can write to the PINS register all day long but if a bit in the DIRS register is 0 then that pin will not be an output, so anything we write to it is meaningless.  This program is flexible in that you can change the masks used and the number of steps in your sequence.  You could also randomize the selection of a mask and the timing for it.  Start with this and let me know if there's anything else I can assist with.

' =========================================================================
'
'   File...... Sequential_Candles.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2006-2009 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 10 FEB 2009
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Candles         = PINS                  ' candle outputs, P0 - P5


' -----[ Constants ]-------------------------------------------------------

SYMBOL  FlickBase       = 20                    ' flicker base timing


' -----[ Variables ]-------------------------------------------------------

SYMBOL  idx             = B2                    ' loop control
SYMBOL  stpIdx          = B3
SYMBOL  rate            = B4                    ' flicker rate

SYMBOL  stpTimer        = W4
SYMBOL  flicker         = W5                    ' random flicker value


' -----[ Initialization ]--------------------------------------------------

Reset:
  stpIdx = 0                                    ' reset
  stpTimer = 0


' -----[ Program Code ]----------------------------------------------------

Main:
  FOR idx = 1 TO 3                              ' tumble random generator
    RANDOM flicker
  NEXT

Flame_On:
  READ stpIdx, DIRS                             ' updata active outputs
  Candles = flicker & %00111111                 ' update outputs
  rate = flicker & $0F + FlickBase              ' randomize timing
  PAUSE rate                                    ' hold flames

Update_Step:
  stpTimer = stpTimer + rate                    ' update step timer
  IF stpTimer < 1500 THEN Main                  ' timer expired?
    stpTimer = 0                                ' yes, reset
    stpIdx = stpIdx + 1                         ' point to next phase
    IF stpIdx = 14 THEN Reset                   ' done with steps?

  GOTO Main                                     ' start again


' -----[ User Data ]-------------------------------------------------------

On_Mask:
  EEPROM (%000000, %000001, %000011, %000111, %001111, %011111, %111111)

OffMask:
  EEPROM (%111111, %111110, %111100, %111000, %110000, %100000, %000000)


Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Here's an idea for randomizing the candles that are active:

' =========================================================================
'
'   File...... Random_Candles.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2006-2009 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 10 FEB 2009
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Candles         = PINS                  ' candle outputs, P0 - P5


' -----[ Constants ]-------------------------------------------------------

SYMBOL  FlickBase       = 20                    ' flicker base timing


' -----[ Variables ]-------------------------------------------------------

SYMBOL  idx             = B2                    ' loop control
SYMBOL  rate            = B3                    ' flicker rate

SYMBOL  stpTimer        = W4
SYMBOL  flicker         = W5                    ' random flicker value


' -----[ Initialization ]--------------------------------------------------

Reset:
  DIRS = %00111111                              ' start with all on


' -----[ Program Code ]----------------------------------------------------

Main:
  FOR idx = 1 TO 3                              ' tumble random generator
    RANDOM flicker
  NEXT

Flame_On:
  Candles = flicker & %00111111                 ' update outputs
  rate = flicker & $0F + FlickBase              ' randomize timing
  PAUSE rate                                    ' hold flames

Update_Step:
  stpTimer = stpTimer + rate                    ' update step timer
  IF stpTimer < 2000 THEN Main                  ' timer expired?
    stpTimer = 0                                ' yes, reset
    DIRS = flicker & %00111111                  ' randomize active candles

  GOTO Main                                     ' start again


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office