November 23, 2024, 10:18:55 AM

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.


Simulating Faulty Wiring to Lamps with Prop-1 and FC-4

Started by JonnyMac, September 17, 2009, 02:33:53 PM

Previous topic - Next topic

JonnyMac

September 17, 2009, 02:33:53 PM Last Edit: September 17, 2009, 02:35:37 PM by JonnyMac
Every year we get requests for a program that simulates faulting wiring to lamps.  I came up with this program that seems to do the trick pretty nicely using a Prop-1 and FC-4.  The program randomly selects and channel which flickers a bit, as if the wiring was breaking or shorting, and then the channel fades up to normal brightness.  The code uses my play list technique so that all the outputs are selected in a cycle before replaying -- and, of course, selection and flicker rate and levels are random.

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


' -----[ Program Description ]---------------------------------------------
'
' Sio :: Serial IO to EFX-TEK accessories (RC-4, FC-4, etc.)
'        -- clip pin 1 of ULN2803 or replace with ULN2003
'
'
' This program randomly flickers one of four lamp channels.  After the
' flickering ends the channel fades back up to normal brightness, as if
' a bad wire had shorted and then the lamp warms back up.


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN


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

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' B/R jumper removed

SYMBOL  FullBright      = 255
SYMBOL  DimLo           = 32
SYMBOL  DimHi           = 128


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

SYMBOL  idx             = B0
SYMBOL  timer           = B1
SYMBOL  chan            = B2
SYMBOL  playList        = B3
SYMBOL  mask            = B4
SYMBOL  lastChan        = B5
SYMBOL  flicks          = B6
SYMBOL  level           = B7

SYMBOL  lottery         = W5


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

Reset:
 lottery = 1031


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

Main:
 SEROUT Sio, Baud, ("!FC4", %00, "A", FullBright)
 GOSUB Randomize                               ' stir random #
 timer = lottery // 51 + 50                    ' 5 to 10 seconds

Loop_Pad:
 PAUSE 98                                      ' pad for 100ms loop
 GOSUB Randomize

Check_Timer:
 IF timer = 0 THEN Select_Channel              ' timer expired?
   timer = timer - 1                           ' no, update
   GOTO Loop_Pad

Select_Channel:
 GOSUB Randomize
 chan = lottery // 4 + 1                       ' ch = 1 to 4
 IF chan = lastChan THEN Select_Channel        ' don't repeat
   lastChan = chan                             ' save for next cycle
   READ chan, mask                             ' convert to mask
   idx = playList & mask                       ' played this cycle?
   IF idx > 0 THEN Select_Channel              ' if yes, try again!
     playList = playList | mask                ' mark played
     IF playList <> %00001111 THEN Set_Flicks  ' all played?
       playList = %00000000                    ' yes, reset

Set_Flicks:
 GOSUB Randomize
 flicks = lottery // 6 + 5                     ' 5 to 10 flicks

Flicker:
 IF flicks = 0 THEN Fade_Up
   GOSUB Randomize
   level = DimHi - DimLo + 1                   ' calculate span
   level = lottery // level + DimLo            ' random flicker level
   SEROUT Sio, Baud, ("!FC4", %00, "L", chan, level)
   PAUSE 9
   flicks = flicks - 1
   GOTO Flicker

Fade_Up:
 IF level >= FullBright THEN Main
   SEROUT Sio, Baud, ("!FC4", %00, "F", chan, level, FullBright, 8)
   GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

Randomize:
 FOR idx = 1 TO 3
   RANDOM lottery
 NEXT
 RETURN

' -------------------------------------------------------------------------


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

Bit_Mask:
 EEPROM (%0000000, %00000001, %00000010, %00000100, %00001000)
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

Jon,

Maybe it's just me, but it looks like the program is missing a chunk in the middle. None of the symbols are defined?
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

Not sure what you're not seeing... I copied that (working) program right out of my editor and into the forum post.  To be sure I just copied it back from the forum to the editor and it compiles fine.  Give it a try!   ;D
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

For some reason it just wasn't displayed properly on the screen in the forum, I hit reply with quote and all the information was there. Sorry. Never mean to doubt you. 
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components