November 23, 2024, 01:58:10 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.


Chandelier Controller Update

Started by Liam, November 10, 2009, 06:44:47 PM

Previous topic - Next topic

Liam

Hi Jon (or whomever would like to assist),

A little over a year ago, you wrote a program for me to flicker the lights on a chandelier using a Prop-1 and FC-4 (do a search for Liam_Flaming_Hangman for a refresher, although I'm going to add the program to this post). It's working great, but in order to get the chandelier bulbs to actually flicker, I need to put a regular light dimmer in between the FC-4 and the chandelier. Which is fine, except that my dimmer died this year, which makes me think it doesn't like the flickering.

My question is - is it possible to limit the values of fire1, fire2, fire3, and fire4 so that the maximum brightness is limited to about 25%? I'm assuming that fireX represents a value between 0-255. Would it be possible to limit it to a value between 0-100 for example? I tried adding lines like "fire1 = fire1 - 100" but that didn't do it. It probably doesn't help that as much as I try to understand this program, I still haven't wrapped my head around it entirely. But I'm trying to, if that counts for anything.

If you need clarification, please feel free to let me know, as my question may not be entirely clear. Thanks very much!

Liam


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


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  PIR             = PIN6                  ' SETUP = DN
SYMBOL  Hangman         = PIN0


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

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

SYMBOL  Baud            = OT2400



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

SYMBOL  state           = B2
SYMBOL  subTimer        = B3

SYMBOL  timer           = W3

SYMBOL  flame1          = W4
SYMBOL   fire1          =  B8
SYMBOL   fire2          =  B9

SYMBOL  flame2          = W5
SYMBOL   fire3          =  B10
SYMBOL   fire4          =  B11


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00000001                              ' make P0-P5 outputs

  flame1 = 1031                                 ' seed

  SEROUT Sio, Baud, ("!!!!!!FC4", %00, "X")     ' resync and reset


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

Main:
  RANDOM flame1
  RANDOM flame2
  SEROUT Sio, Baud, ("!FC4", %00, "S", fire1, fire2, fire3, fire4)
  timer = timer + 42

  BRANCH state, (Check_PIR, Thrash, Rest)

State_Error:
  timer = 0
  state = 0
  GOTO Main

Check_PIR:
  timer = timer * PIR                           ' scan PIR
  IF timer < 100 THEN Main                      ' valid signal
    state = 1                                   ' yes, advance state
    timer = 0                                   ' reset timer for next state
    subTimer = 0
    GOTO Main

Thrash:
  subTimer = subTimer + 1                       ' update subTimer
  IF subTimer < 6 THEN Thrash_Check             ' 1/4 second?
    Hangman = flame1                            ' yes, thrash about
    subTimer = 0                                ' reset subTimer

Thrash_Check:
  IF timer < 8000 THEN Main                     ' for eight seconds
    state = 2
    timer = 0
    GOTO Main

Rest:
  Hangman = IsOff                               ' rest
  IF timer < 15000 THEN Main                    ' for 15 seconds
    state = 0
    timer = 0
    GOTO Main


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


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


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

JonnyMac

Since the BS1 uses 16-bit values internally you can do something like this:

level = level * 100 / 255

This will scale the level to 0 to 100.  If you decide that 100 isn't the right value just change that part of the equation. 

Your subtraction trick only worked with values greater than 100, when less you'd actually get a roll-under error that caused the value to be greater than 100 (tough to explain in words, if I had a white board it would be easy -- so trust me!).
Jon McPhalen
EFX-TEK Hollywood Office

Liam

Very cool, thanks very much Jon! I definitely trust you on that, thanks for the explanation.

Liam