November 21, 2024, 07:25:24 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.


Wick led Code

Started by JCrank, October 25, 2007, 07:19:57 PM

Previous topic - Next topic

JCrank

Hello I just received my Prop-2.  Is there code for the Wick LEDs for the Prop-2

JonnyMac

There is now! -- this is a 1-for-1 translation of the BS1 program.

' =========================================================================
'
'   File...... Candles.BS2
'   Purpose... Light faux candles (with LED wicks)
'   Author.... EFX-TEK (www.efx-tek.com)
'              Copyright (c) 2007 EFX-TEK
'   E-mail.... teamefx@efx-tek.com
'   Started...
'   Updated... 25 OCT 2007
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' This program controls up to 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 Prop-1 controller output goes off,
' creating a more realistic flame effect.


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

Candles         VAR     OUTL                    ' candle outputs, P0 - P5


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

FlickBase       CON     20                      ' flicker base timing


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

flicker         VAR     Word                    ' random flicker value
idx             VAR     Byte                    ' loop control
wicks           VAR     Byte                    ' to test for dark
rate            VAR     Byte                    ' flicker rate


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

Reset:
  DIRL = %00111111                              ' make P0 - P5 outputs
  flicker = 1225                                ' seed random generator


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

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

Check_Dark:
  wicks = flicker & %00111111                   ' test value
  IF wicks = %000000 THEN Main                  ' if all off, try again

Flame_On:
  Candles = wicks                               ' update outputs
  rate = flicker & $0F + FlickBase              ' randomize timing
  PAUSE rate                                    ' hold flames
  GOTO Main                                     ' start again
Jon McPhalen
EFX-TEK Hollywood Office

JCrank

Thanks for the quick responce,

This may be a dumb question, but this is my first experiance with the BS2.

What is the %00111111 and $0F referring to?  Is it memory locations?

JonnyMac

No, those are called masks; in this line:

  wicks = flicker & %00111111

... the latter half (starting with '&') copies the value of flicker, strips off all but the lower six bits, then copies the updated value to wicks.  You can read about the & operator in the help file -- it will make more sense.

This line:

  rate = flicker & $0F + FlickBase

... is doing the same thing, but with the lower four bits of flicker; $0F is the same as %00001111.  The first part of that line limits the value to 15 (%1111 = 15) then adds that to FlickBase (which is 20 in this program); the result is that rate will be a random value between 20 and 35.

Jon McPhalen
EFX-TEK Hollywood Office

JCrank

Ok that explains allot  :)