November 21, 2024, 11:28:39 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Flickering Shop Lights

Started by LPFreak1283, September 12, 2016, 01:05:39 PM

Previous topic - Next topic

LPFreak1283

I built LED shoplights a few years back and used some Prop-1's to run a simple blinking program that I wrote in Vixen.  It worked well, but I wanted a electrical/dying bulb look.  So I did some searching on the forums and was reading up on this thread:

http://www.efx-tek.com/php/smf/index.php?topic=2079.0

So I decided to try it and the effect was very convincing on the bulbs, but all four lights flickered at once.  So I re-wrote the program and now I get single bulb flickering. 

https://youtu.be/_CfcuovHS-s

Here is the program:

' =========================================================================
'
'   File...... Flickering LED Shop lights (4)
'   Purpose...
'   Author.... Cory Baumgart
'   E-mail.... corymbaumgart@gmail.com
'   Started... 9/8/2016
'   Updated... 9/12/2016
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


' -----[ Revision History ]------------------------------------------------
' 1.0 - Original version designed by Jon Williams and Jukingeo
' 2.0 - Re-written by myself to include 4 separate bulbs flickering

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

SYMBOL  Trigger         = PIN7                  ' SETUP = DN
SYMBOL  Lights          = PINS                  ' use P0..P5
SYMBOL  Bulb1           = 0
SYMBOL  Bulb2           = 1
SYMBOL  Bulb3           = 2
SYMBOL  Bulb4           = 3
SYMBOL  Ambers1         = 4
SYMBOL  Ambers2         = 5


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

SYMBOL  Yes             = 1
SYMBOL  IsOn            = 1
SYMBOL  No              = 0
SYMBOL  IsOff           = 0

SYMBOL  AllWhitesOn     = %00001111             ' all lamps on (change 0 to 1 to add more)
SYMBOL  AllOff          = %00000000             ' all lamps off
SYMBOL  BulbOne         = %00000001
SYMBOL  BulbTwo         = %00000010
SYMBOL  BulbThree       = %00000100
SYMBOL  BulbFour        = %00001000
SYMBOL  AmbersOne       = %00010000
SYMBOL  AmbersTwo       = %00100000


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

SYMBOL  idx             = B2                    ' loop control
SYMBOL  flicks          = B3                    ' flick events
SYMBOL  flkDelay        = B4                    ' delay between flickers
SYMBOL  timer           = B5                    ' for variable delays
SYMBOL  lottery         = W5                    ' random value
SYMBOL  bulblot         = W3                    ' random value for bulbset
SYMBOL  bulbset         = B8


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

Reset:
  PINS = %00000000
  DIRS = %00111111                              ' allow all on
  Lights = AllWhitesOn

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

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

  IF flkDelay = 0 THEN Flicker_Cycle
    PAUSE 25
    flkDelay = flkDelay - 1
    GOTO Main

Flicker_Cycle:
  RANDOM lottery                                ' stir again
  flicks = lottery // 10 + 3                    ' 2 to 5 flicks (changed from 1 to 4 flicks)

Bulb_Select:
  RANDOM bulblot
  bulbset = bulblot // 4 + 1                    ' 1 to 4 bulb

Flicker:
  IF bulbset = 1 THEN Set1
  IF bulbset = 2 THEN Set2
  IF bulbset = 3 THEN Set3
  IF bulbset = 4 THEN Set4

Reset_Flicker_Timer:
  RANDOM lottery
  flkDelay = 81 + 40                           ' set 1 to 3 seconds
  PAUSE 4000                                   ' Pause 4 seconds before flicking again
  GOTO Main                                    ' Let's go again!

' -----[ Subroutines ]-----------------------------------------------------
Set1:
  FOR idx = 1 TO 2
    LOW Bulb1                                   ' light out
    RANDOM lottery
    timer = lottery // 46 + 5                   ' 5 to 45 ms (orig set to 26 + 10)
    PAUSE timer
    HIGH Bulb1                                  ' back on
    RANDOM lottery
    timer = lottery // 71 + 50                  ' 50 to 100 ms (orig set to 51 + 51)
    PAUSE timer
  NEXT
  flicks = flicks - 1
  IF flicks > 0 THEN Set1                       ' finished?
  RETURN

Set2:
  FOR idx = 1 TO 2
    LOW Bulb2                                   ' light out
    RANDOM lottery
    timer = lottery // 46 + 5                   ' 5 to 45 ms (orig set to 26 + 10)
    PAUSE timer
    HIGH Bulb2                                  ' back on
    RANDOM lottery
    timer = lottery // 71 + 50                  ' 50 to 100 ms (orig set to 51 + 51)
    PAUSE timer
  NEXT
  flicks = flicks - 1
  IF flicks > 0 THEN Set2                       ' finished?
  RETURN

Set3:
  FOR idx = 1 TO 2
    LOW Bulb3                                   ' light out
    RANDOM lottery
    timer = lottery // 46 + 5                   ' 5 to 45 ms (orig set to 26 + 10)
    PAUSE timer
    HIGH Bulb3                                  ' back on
    RANDOM lottery
    timer = lottery // 71 + 50                  ' 50 to 100 ms (orig set to 51 + 51)
    PAUSE timer
  NEXT
  flicks = flicks - 1
  IF flicks > 0 THEN Set3                       ' finished?
  RETURN

Set4:
  FOR idx = 1 TO 2
    LOW Bulb4                                   ' light out
    RANDOM lottery
    timer = lottery // 46 + 5                   ' 5 to 45 ms (orig set to 26 + 10)
    PAUSE timer
    HIGH Bulb4                                  ' back on
    RANDOM lottery
    timer = lottery // 71 + 50                  ' 50 to 100 ms (orig set to 51 + 51)
    PAUSE timer
  NEXT
  flicks = flicks - 1
  IF flicks > 0 THEN Set4                       ' finished?
  RETURN
' -----[ EEPROM Data ]-----------------------------------------------------


Now I would actually like to include a trigger option to this.  I have a Prop-2 that runs my medical patient.  I have added some code to that to send a 'trigger' to the prop one on Pin7.  It is set (on the Prop-2) for a 200ms press.  I have gotten it to work on a very basic level using the bs1 template.  But can I run this program while monitoring a trigger? 

JonnyMac

September 13, 2016, 10:01:13 AM #1 Last Edit: September 14, 2016, 08:36:38 AM by JonnyMac
Even with a lot of experience, I sometimes find it tricky to get into the head of another programmer simply by looking at his/her code. If you would, please explain what you want the final outcome to be (as if the program hasn't been written) and I'll give it a crack. Between my code and yours, I think you'll find a solution.

Tip: If you have redundant code, look for opportunities to consolidate into a subroutine. You have four subroutines that do exactly the same thing -- other than the bulb being controlled. You can distill these to one subroutine and use the variable bulbset where you had the bulb constant. This frees up a fair bit of space in your program.

I don't know if this is what you're after, but it is a working program. The lights are solid until a trigger is detected (I used P6 so that I could test with a Trainer Board). When a valid trigger is detected, the flicker code runs.

' =========================================================================
'
'   File...... Flickering LED Shop lights (4)
'   Purpose...
'   Author.... Cory Baumgart
'   E-mail.... corymbaumgart@gmail.com
'   Started... 9/8/2016
'   Updated... 9/12/2016
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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

' 1.0 - Original version designed by Jon McPhalen and Jukingeo
' 2.0 - Re-written by myself to include 4 separate bulbs flickering
' 2.1 - Updated by Jon McPhalen to reduce code and add trigger


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Lights          = PINS                  ' use P0..P5
SYMBOL  Ambers2         = 5
SYMBOL  Ambers1         = 4
SYMBOL  Bulb4           = 3
SYMBOL  Bulb3           = 2
SYMBOL  Bulb2           = 1
SYMBOL  Bulb1           = 0


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

SYMBOL  Yes             = 1
SYMBOL  IsOn            = 1
SYMBOL  No              = 0
SYMBOL  IsOff           = 0

SYMBOL  AllWhitesOn     = %00001111             ' all lamps on
SYMBOL  AllOff          = %00000000             ' all lamps off

SYMBOL  BulbOne         = %00000001
SYMBOL  BulbTwo         = %00000010
SYMBOL  BulbThree       = %00000100
SYMBOL  BulbFour        = %00001000

SYMBOL  AmbersOne       = %00010000
SYMBOL  AmbersTwo       = %00100000


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

SYMBOL  timer           = B2                    ' for variable delays
SYMBOL  idx             = B3                    ' loop control
SYMBOL  flicks          = B4                    ' flick events
SYMBOL  flkDelay        = B5                    ' delay between flickers
SYMBOL  bulbset         = B6                    ' bulb to flicker

SYMBOL  lottery         = W5                    ' random value


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

Reset:
  PINS = %00000000
  DIRS = %00001111                              ' allow all on


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

Main:
  Lights = AllWhitesOn
  timer = 0

Wait_Trigger:
  RANDOM lottery                                ' stir random #
  PAUSE 10                                      ' hold a bit
  IF Trigger = 0 THEN Main                      ' no trigger, start over
    timer = timer + 10                          ' update debounce timer
  IF timer < 100 THEN Wait_Trigger              ' fully debounced

Flicker_Cycle:
  RANDOM lottery                                ' stir again
  flicks = lottery // 10 + 3                    ' 3 to 12 flicks

Bulb_Select:
  RANDOM lottery
  bulbset = lottery // 4                        ' 0 to 3 (Bulb 1 to 4)
  GOSUB Flicker_Bulb

  GOTO Reset


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

' Flicker selected bulb
' -- bulbset holds bulb to flicker
' -- flicks holds flicker cycles

Flicker_Bulb:
  FOR idx = 1 TO 2
    LOW bulbset                                 ' light out
    RANDOM lottery
    timer = lottery // 46 + 5                   ' 5 to 50ms
    PAUSE timer
    HIGH bulbset                                ' back on
    RANDOM lottery
    timer = lottery // 71 + 50                  ' 50 to 120ms
    PAUSE timer
  NEXT
  flicks = flicks - 1
  IF flicks > 0 THEN Flicker_Bulb               ' finished?
  RETURN


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


BTW... there is a problem in your program that may cause things to go haywire: You are doing an implied GOTO to Set1, Set2, etc, but coming back with RETURN. RETURN should only be used with GOSUB.
Jon McPhalen
EFX-TEK Hollywood Office

LPFreak1283

Jon, that makes complete sense program wise. I guess I need to drink more coffee before trying to code! Haha.

So what I want to accomplish is that the lights flicker while waiting for a trigger input from the prop-2. Once that happens, I want the lights to go haywire. Once a specified amount if time passes, the lights calm back down. Now when I built my lights I included orange bulbs at the ends of the bulbs to look like the lights are warming up. I put the pins in the code but I'm not sure if I'll use them of not.
Hope that helps!

JonnyMac

Okay, give this a crack.

' =========================================================================
'
'   File...... Flickering LED Shop lights (4)
'   Purpose...
'   Author.... Cory Baumgart
'   E-mail.... corymbaumgart@gmail.com
'   Started... 9/8/2016
'   Updated... 9/15/2016
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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

' 1.0 - Original version designed by Jon McPhalen and Jukingeo
' 2.0 - Re-written by myself to include 4 separate bulbs flickering
' 2.1 - Updated by Jon McPhalen to reduce code and add trigger
'       -- trigger causes all lamps to freak out


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Lights          = PINS                  ' use P0..P5
SYMBOL  Ambers2         = 5
SYMBOL  Ambers1         = 4
SYMBOL  Bulb4           = 3
SYMBOL  Bulb3           = 2
SYMBOL  Bulb2           = 1
SYMBOL  Bulb1           = 0


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

SYMBOL  Yes             = 1
SYMBOL  IsOn            = 1

SYMBOL  No              = 0
SYMBOL  IsOff           = 0

SYMBOL  AllWhitesOn     = %00001111             ' all lamps on
SYMBOL  AllOff          = %00000000             ' all lamps off

SYMBOL  BulbOne         = %00000001
SYMBOL  BulbTwo         = %00000010
SYMBOL  BulbThree       = %00000100
SYMBOL  BulbFour        = %00001000

SYMBOL  AmbersOne       = %00010000
SYMBOL  AmbersTwo       = %00100000

SYMBOL  FreakOutMillis  = 5000


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

SYMBOL  idx             = B2                    ' loop control
SYMBOL  flicks          = B3                    ' flick events
SYMBOL  flkDelay        = B4                    ' delay between flickers
SYMBOL  bulbset         = B5                    ' bulb to flicker
SYMBOL  delay           = B6

SYMBOL  timer           = W4
SYMBOL  lottery         = W5                    ' random value


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

Reset:
  PINS = AllWhitesOn
  DIRS = %00001111                              ' allow all on


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

Main:
  timer = 0
  FOR idx = 1 TO 10
    PAUSE 10
    timer = timer + 10 * Trigger                ' bump by 10 when Trigger on
  NEXT
  IF timer < 100 THEN Flicker_Cycle


Freak_Out:
  timer = 0

FO_Loop:
  RANDOM lottery
  Lights = lottery & %1111                      ' randomize lamps
  RANDOM lottery
  delay = lottery // 21 + 5                     ' 5 to 25ms
  PAUSE delay
  timer = timer + delay
  IF timer < FreakOutMillis THEN FO_Loop        ' time left?

FO_Exit:
  Lights = AllWhitesOn
  GOTO Inter_Bulb_Gap


Flicker_Cycle:
  RANDOM lottery                                ' stir again
  flicks = lottery // 10 + 3                    ' 3 to 12 flicks

Bulb_Select:
  RANDOM lottery
  bulbset = lottery // 4                        ' 0 to 3 (Bulb 1 to 4)
  GOSUB Flicker_Bulb

Inter_Bulb_Gap:
  RANDOM lottery
  delay = lottery // 401 + 100                  ' 100 to 500 (x10 = 1s-5s)

IBG_Loop:
  IF Trigger = Yes THEN Reset                   ' trigger hot?
  PAUSE 10
  delay = delay - 1
  IF delay > 0 THEN IBG_Loop

  GOTO Reset


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

' Flicker selected bulb
' -- bulbset holds bulb to flicker
' -- flicks holds flicker cycles

Flicker_Bulb:
  FOR idx = 1 TO 2
    LOW bulbset                                 ' light out
    RANDOM lottery
    delay = lottery // 46 + 5                   ' 5 to 50ms
    IF Trigger = IsOn THEN FB_Exit              ' check early exit
    PAUSE delay
    HIGH bulbset                                ' back on
    RANDOM lottery
    delay = lottery // 71 + 50                  ' 50 to 120ms
    IF Trigger = IsOn THEN FB_Exit              ' check early exit
    PAUSE delay
  NEXT
  flicks = flicks - 1
  IF flicks > 0 THEN Flicker_Bulb               ' finished?

FB_Exit:
  RETURN

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

LPFreak1283

Jon,

That worked absolutely amazing!  I'll post a video soon so you can see the effect!  Thank you so much!

Cory

livinlowe

Quote from: LPFreak1283 on September 12, 2016, 01:05:39 PM
I built LED shoplights a few years back and used some Prop-1's to run a simple blinking program that I wrote in Vixen....

Just curious, how did you build these lights?
Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

Quote from: LPFreak1283 on September 16, 2016, 03:56:45 PM
Jon,

That worked absolutely amazing!  I'll post a video soon so you can see the effect!  Thank you so much!

Cory

Excellent! I rule! :)

Joking aside, I'm glad I could assist.
Jon McPhalen
EFX-TEK Hollywood Office

LPFreak1283

Quote from: livinlowe on September 16, 2016, 05:21:59 PM
Just curious, how did you build these lights?

I bought florescent bulb protectors and spray painted them white.  Then I purchased small breadbroards and cut them in half.  I then soldered 48 LEDs in parallel (12 sets of 4 leds).  That gave me ~200 ma draw per "bulb" at 12v.  I also added one amber bulb at each end to make it appear that the bulb was warming up.  I added quick connects to the ends to hook the "bulbs" to the Prop-1.  I slid the prepared boards into the protectors and zip tied them.

Here are the lights being built:







I had two bad florescent light holders so I removed the guts, cut the wires inside, and mounted the Prop-1 inside the casing.  This allowed me to use the original power wire going to the light for power.  I mounted the wall wart to the top of the light.  They actually look really neat and I get alot of comments on the over Halloween night. 

JonnyMac

Nicely done!

At Alliance Studio (Steve Wang's shop) we use a lot of 12V strip light. If you're in a hurry and have the budget, it's a great way to go.

--> http://www.allelectronics.com/item/ls-12-cw/12-vdc-led-light-strip-cool-white/1.html

We recently control more than 100 feet of this stuff that was laid together in sections and overlapped. I created a wave pattern (by linking 4 HC-8+ controllers) to create a ghost effect. It really turned out well. For you gamers, it was the Lucian character for Riot Games. You can see pictures of the piece in this thread:

-- http://www.efx-tek.com/php/smf/index.php?topic=2305.0

There's video here, but the camera person was wobbly so it's a bit hard to see the effect.

-- https://www.youtube.com/watch?v=IQ5Z3kFsi8U
Jon McPhalen
EFX-TEK Hollywood Office