November 22, 2024, 01:45:38 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.


Random flicker with FC-4

Started by Liam, December 09, 2007, 07:17:06 PM

Previous topic - Next topic

Liam

Hi Jon,

I just received my two FC-4 boards, and they're great. I was wondering if it would be possible to create a random flicker with an FC-4? I would like to create the effect of incandescent bulbs powered by an inconsistent power source. It seems that there must be a way, but I'm not sure exactly how to do it. If this isn't clear enough I can try to explain it in better terms, just let me know.

Thanks very much,
Liam

JonnyMac

Hmmm... going after a "fire" effect?  Here's a really simple program:

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


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN


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

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


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

SYMBOL  lottery1        = W1
SYMBOL   lamp1          = B2
SYMBOL   lamp2          = B3

SYMBOL  lottery2        = W2
SYMBOL   lamp3          = B4
SYMBOL   lamp4          = B5


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

Reset:
  lottery1 = 1225                               ' seed the random values
  lottery2 = 0725


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

Main:
  RANDOM lottery1
  RANDOM lottery2
  SEROUT Sio, OT2400, ("!FC4", %00, "S", lamp1, lamp2, lamp3, lamp4)
  GOTO Main


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


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


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

JonnyMac

And another....

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


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN


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

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

SYMBOL  Up              = 1
SYMBOL  Down            = 0


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

SYMBOL  level           = B0
SYMBOL   direction      = BIT5

SYMBOL  idx             = B1

SYMBOL  lamp1           = B2
SYMBOL  lamp2           = B3
SYMBOL  lamp3           = B4
SYMBOL  lamp4           = B5
SYMBOL  lottery         = W5                    ' random value


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

Reset:
  lottery = 1225                                ' seed the random value

  lamp1 = 12
  lamp2 = 250
  lamp3 = 31
  lamp4 = 100


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

Main:
  GOSUB Stir_It_Up
  IF direction = Up THEN Bump_1

Dec_1:
  lamp1 = lamp1 - level
  GOTO Check_2

Bump_1:
  direction = 0
  lamp1 = lamp1 + level


Check_2:
  GOSUB Stir_It_Up
  IF direction = Up THEN Bump_2

Dec_2:
  lamp2 = lamp2 - level
  GOTO Check_3

Bump_2:
  direction = 0
  lamp2 = lamp2 + level


Check_3:
  GOSUB Stir_It_Up
  IF direction = Up THEN Bump_3

Dec_3:
  lamp3 = lamp3 - level
  GOTO Check_4

Bump_3:
  direction = 0
  lamp3 = lamp3 + level


Check_4:
  GOSUB Stir_It_Up
  IF direction = Up THEN Bump_4

Dec_4:
  lamp4 = lamp4 - level
  GOTO Update_Lamps

Bump_4:
  direction = 0
  lamp4 = lamp4 + level


Update_Lamps:
  SEROUT Sio, OT2400, ("!FC4", %00, "S", lamp1, lamp2, lamp3, lamp4)
  GOTO Main


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

Stir_It_Up:
  FOR idx = 1 TO 3
    RANDOM lottery
  NEXT
  level = lottery // 32
  RETURN


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

JonnyMac

Okay, one more for good measure -- play with them all, adjust, tweak, and prod until you get the effect you're after.

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


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN


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

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

SYMBOL  Speed           = 7


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

SYMBOL  advance         = B0
SYMBOL  pntr1           = B1
SYMBOL  pntr2           = B2
SYMBOL  pntr3           = B3
SYMBOL  pntr4           = B4
SYMBOL  level1          = B5
SYMBOL  level2          = B6
SYMBOL  level3          = B7
SYMBOL  level4          = B8

SYMBOL  lottery         = W5                    ' random value


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

Reset:
  lottery = 1225                                ' seed the random value


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

Main:
  RANDOM lottery
  advance = lottery // Speed + 1
  pntr1 = pntr1 + advance // 102
  READ pntr1, level1

  RANDOM lottery
  advance = lottery // Speed + 1
  pntr2 = pntr2 + advance // 102
  READ pntr2, level2

  RANDOM lottery
  advance = lottery // Speed + 1
  pntr3 = pntr3 + advance // 102
  READ pntr3, level3

  RANDOM lottery
  advance = lottery // Speed + 1
  pntr4 = pntr4 + advance // 102
  READ pntr4, level4

  SEROUT Sio, OT2400, ("!FC4", %00, "S", level1, level2, level3, level4)

  GOTO Main


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


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


' -----[ User EEPROM ]-----------------------------------------------------

Glow_Table:
  EEPROM (000, 016, 031, 046, 060, 073, 085, 096)
  EEPROM (106, 113, 120, 124, 126, 127, 126, 122)
  EEPROM (117, 111, 102, 092, 081, 068, 054, 040)
  EEPROM (025, 009, 250, 234, 219, 205, 191, 178)
  EEPROM (166, 156, 147, 140, 134, 131, 129, 129)
  EEPROM (131, 135, 141, 149, 158, 168, 180, 193)
  EEPROM (207, 222, 237, 253, 237, 222, 207, 193)
  EEPROM (180, 168, 158, 149, 141, 135, 131, 129)
  EEPROM (129, 131, 134, 140, 147, 156, 166, 178)
  EEPROM (191, 205, 219, 234, 250, 009, 025, 040)
  EEPROM (054, 068, 081, 092, 102, 111, 117, 122)
  EEPROM (126, 127, 126, 124, 120, 113, 106, 096)
  EEPROM (085, 073, 060, 046, 031, 016)
Jon McPhalen
EFX-TEK Hollywood Office

Liam

Thanks, Jon! That will give me plenty to work with. Much appreciated as always, you guys are great.

Liam

gadget-evilusions

I loaded all three programs, and they do completely different effects on the lights, that is great. My question is, do the trigger and pot connections do anything to the program. I see them assigned locations but they don't seem to actually do anything to the effect on the lights.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

No, those were in my template -- you could certainly add that functionality to the program(s).
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

Ok, I just wanted to make sure. I didnt see where they were doing anything, and wanted to make sure I wasnt doing anything silly. Additional question. On version one of the above three programs, would it be possible to set minimum and maximum brightness levels? I would like to be able to do it two ways if possible.

#1 I would like to be able to just modify two values in the code.

#2 I would like to be able to use two pots, one to control min, and one to control max.

IF this is super time consuming don't worry about it, but I have applications coming up where both would be helpful. Our commercial haunted attraction is reopening in 2008 and I am planning out the special effects already.

Thank you
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

December 14, 2007, 09:26:54 AM #8 Last Edit: December 14, 2007, 09:28:56 AM by JonnyMac
1) It's easy -- once you wrap you head around the technique -- to setup minimum and maximum levels from a random source; we use the modulus operator.  Let's say you want the brightness levels to fall between 25 and 200; you'd do it like this:

  brightness = lottery // 176 + 25

The last value is the minimum.  The divisor for the modulus operator is equal to the maximum level minus the minimum plus one.  Don't forget the plus one part because modulus ( // ) always returns a value between 0 and the divisor minus one.


2) You could easily read two pots (you know how to do that) and then sub in the values.  Lets say you want your minimum level to fall between 25 and 100.  You could take the raw pot reading and adjust it like this:

  minLevel = rawPot ** $4B4B + 25

What?!  I'm using another sneaky math trick: The ** operator is like multiplying by a fractional value expressed in units of 1/65536.  What I want to do for the minimum level is convert the raw pot input (0 to 255) to a value between 0 and 75.  Why?  Because that is the span between 100 and 25 (100 - 25 = 75).  If I divide 255 (max pot value) into 75 (span) I get 0.294.  Now take this value and multiply it by 65536 -- this becomes the multiplier for **.  I like to convert things to hex notation for ** as this reminds me that it's not a normal multiplication.

Since this can be a little brain-bending, I'll do the max version for you, too.  Let's say for the max pot you want the value to go between 151 (just above the min) and 255.  Here's the math:

  maxLevel = rawPot ** $6868 + 151

The multiplier for is calculated thusly:
  -- 255 - 151 = 104 (this is the span)
  -- 104 / 255 = 0.407 (multiplier to convert raw pot input to span)
  -- 0.407 * 65536 = 26725 (hex notation is $6868)

Finally... how do we put this into a program:

1) Read min pot and calculate min level as above
2) Read max pot and calculate max level as above
3) Use this formula:

  span = maxLevel - minLevel + 1
  brightness = lottery // span + minLevel


Now... don't be tempted to use the MIN and MAX operators for this stuff; those operators truncate values and will therefore truncate the range of your potentiometer (there will come a point where you can keep turning, but the value doesn't change).  By spending a couple minutes with our calculator we can use the full range of the pot for setting levels.
Jon McPhalen
EFX-TEK Hollywood Office

samsam

JonnyMac

Could you also write them for a Basic Stamp 2

Thank You for your time and help in this matter
Sam

I Want  Thank You for All Of Your Time And Help

...............In Helping Getting Thing To Work........

JonnyMac

The code is almost identical.  You should give it a try first, and then let me help you if you can't get it to work -- that's the best way to learn.  I know that you know how to program the BS2, Sam, so give it a try!
Jon McPhalen
EFX-TEK Hollywood Office