November 23, 2024, 10:44:48 PM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Double random?

Started by Karl Fields, May 23, 2011, 10:09:19 PM

Previous topic - Next topic

Karl Fields

I have a need (I think) for a double random generator. I have 8 sets of  grain of wheat lamps that I want to randomly (or pseudo) turn on and off. The length of time they are on also needs to be random. Maybe 3 seconds at the longest and just a flash at the shortest time interval. Somehow I would also like to have ability to turn on more than one output at a time. I am thinking that I will make varied intensity by putting another lamp either parallel or in series with the original.

Think starlit sky...

JonnyMac

Just randomize the outputs and then create a random time.  Keep in mind that some bits will stay on between cycles so this will extend their apparent timing -- you might have a shorter max time spec for this behavior.  This is the basic candle program that does just that.

You'll want to experiment with the TmMin and TmMax values in this program.


' =========================================================================
'
'   File...... Candles.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


' -----[ Revision History ]------------------------------------------------


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

SYMBOL  Wicks           = PINS


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

SYMBOL  TmMin           = 25
SYMBOL  TmMax           = 75


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

SYMBOL  idx             = B2

SYMBOL  delay           = W4
SYMBOL  lottery         = W5


' -----[ EEPROM Data ]-----------------------------------------------------


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

Reset:
 DIRS = %00111111
 lottery = 1031                                ' seed random value


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

Main:
 FOR idx = 1 TO 3                              ' stir random value
   RANDOM lottery
 NEXT

 Wicks = lottery

 delay = TmMax - TmMin + 1                     ' calculate span
 delay = lottery // delay + TmMin              ' calculate delay
 PAUSE delay                                   ' wait
 GOTO Main
Jon McPhalen
EFX-TEK Hollywood Office