November 23, 2024, 11:46:44 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.


Fire Flies 2

Started by steveo, August 27, 2007, 09:25:59 AM

Previous topic - Next topic

steveo

'My version of JonnyMac's very cool fireflies program. The intent of this version was to randomize the PWM ramp-up and down times to make the fireflies more natural. The "playlist" was also removed.


'=========================================================================
'
'   File: fire_flies2
'   Purpose: A different take on the "fire flies" LED program
'   Author: Steve O'Connor
'   E-mail: steveo@garageofevil.com
'   Started: August 27, 2007
'   Updated: N/A
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'   {$PORT COM1}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
' My version of JonnyMac's very cool fireflies program. The intent of this
' version was to randomize the PWM ramp-up and down times to make the fireflies
' more natural. The "playlist" was also removed.

' -----[ Revision History ]------------------------------------------------
' N/A
' -----[ Variables ]-------------------------------------------------------

SYMBOL      Bug           = B2
SYMBOL      Lottery       = W5
SYMBOL      Brightness    = B4
SYMBOL      PINCheck      = B3
SYMBOL      WaitTime      = W6
SYMBOL      Duration      = B1
SYMBOL      Duration_Stir = B8
SYMBOL      Startdur      = B7



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

Main:

FOR Duration_Stir = 1 TO 10                           'Stir the variables up

RANDOM Duration
RANDOM startdur
RANDOM Lottery
NEXT

Bug = Lottery // 6
Startdur = Startdur // 255
Duration = Duration // 256 + 150

IF PINCheck = Bug THEN Main                           'Don't light the same Bug
                                                      'twice in a row

  FOR Brightness = Startdur TO Duration STEP 1        'Light the Bug
    PWM  Bug, Brightness, 1
  NEXT

HIGH Bug
PAUSE 300

  FOR Brightness = Duration TO Startdur STEP -1       'Fade the Bug
    PWM  Bug, Brightness, 1
  NEXT

RANDOM Lottery                                        'Stir Lottery again
WaitTime = Lottery // 250 + 500                       'Use Lottery value for the
PAUSE WaitTime                                        'time between Bugs being lit

PINCheck = Bug                                        'Remember which Bug lit last

GOTO Main



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



livinlowe

Can you post a video? I would love to see the effect! :D
Shawn
Scaring someone with a prop you built -- priceless!

steveo

I don't have a capture card unfortunately.

Attach the trainer board and load into your prop1 is about as good as I can do for you.

JonnyMac

Here's another bit of code to consider.  It controls the firefly speed by randomizing the step size for the FOR-NEXT loop; I think this is what you're looking for as you go from full-off to full-on (and vice-versa), just at different speeds.  By starting the cycle in the middle you get a bit of steppiness that, to my eye, anyway, doesn't appear completely natural.


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


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


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


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

SYMBOL  idx             = B2                    ' loop controller
SYMBOL  theBug          = B3                    ' pin to light
SYMBOL  last            = B4                    ' last pin lit
SYMBOL  stpSize         = B5                    ' to control PWM speed
SYMBOL  level           = B6                    ' brightness level
SYMBOL  delay           = W4
SYMBOL  lottery         = W5                    ' random value


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

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

  theBug = lottery // 6                         ' select pin, 0 to 5
  IF theBug = last THEN Main                    ' don't repeat
    last = theBug                               ' save for next cycle

Bug_On:
  RANDOM lottery
  stpSize = lottery // 8 + 1                    ' randomize loop speed
  FOR level = 0 TO 255 STEP stpSize             ' brighten
    PWM theBug, level, 1
  NEXT
  HIGH theBug

On_Time:
  RANDOM lottery
  delay = lottery // 151 + 50                   ' 150 to 300 ms
  PAUSE delay

Bug_Off:
  RANDOM lottery
  stpSize = lottery // stpSize + 1              ' off no slower than on
  FOR level = 255 TO 0 STEP -stpSize
    PWM theBug, level, 1
  NEXT
  LOW theBug

Off_Time:
  RANDOM lottery
  delay = lottery // 250 + 500
  PAUSE delay
  GOTO Main

' -------------------------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

steveo

Very cool. Thanks Jon!

On a completely different note, when testing your RC4 to control a high power fog machine, don't screw up leave the output high. I'm still surprised the fire trucks didn't come by the time I had it unplugged.

Love that little RC4.

JonnyMac

Please don't change the topic of a thread midstream.....
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Quote from: livinlowe on August 27, 2007, 09:43:14 AM
Can you post a video? I would love to see the effect! :D

I shot some low-resolution footage with my camera phone; you can see my program running here: http://www.efx-tek.com/videos/fireflies.mov
Jon McPhalen
EFX-TEK Hollywood Office

Jeff Haas

I'm going through old topics, reading up on things and generally educating myself.  The video clip mentioned in the above post isn't there any more.  Is it still around?

gravediggergreg

looks great thank you.   

I think i understand that v2 code

theBug = lottery // 6                       

only runs 6 lights and needs to me changed to

theBug = lottery // 8                       

would it be possible to put in a all bulbs on test routine when first turned on (kinda like the dash of my car when first started?).  after hanging feets of wire, and light bulbs swinging around during install or day of event, it would be nice if the first 15 seconds when the unit is turned on there was a quick visual confirmation that everything is working, without having to stand there waiting for a random bulb to kick on.   

again thanks for the code and the help, this is my first attempt at using the prop1, cool i see more in the future!

JonnyMac

October 22, 2009, 08:50:16 AM #9 Last Edit: October 22, 2009, 08:55:07 AM by JonnyMac
Here' you go.  I made the test section run like I've seen some electronics: all elements on to start with and then we loop through each individual channel.  The second part of the test is there to ensure there are no shorted wires between channels.

' =========================================================================
'
'   File...... Firefly3.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 22 OCT 2009
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  idx             = B2                    ' loop controller
SYMBOL  theBug          = B3                    ' pin to light
SYMBOL  last            = B4                    ' last pin lit
SYMBOL  stpSize         = B5                    ' to control PWM speed
SYMBOL  level           = B6                    ' brightness level
SYMBOL  delay           = W4
SYMBOL  lottery         = W5                    ' random value


' -----[ Test Routine ]----------------------------------------------------

Test_Bugs:
  PINS = %11111111                              ' all on
  DIRS = %11111111
  PAUSE 2000
  PINS = %00000000                              ' all off
  PAUSE 1000

  FOR theBug = 0 TO 7                           ' test each individually
    HIGH theBug                                 ' turn it on
    PAUSE 1000                                  ' for 1 second
    LOW theBug
  NEXT
  PAUSE 1000


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

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

 theBug = lottery // 8                         ' select pin, 0 to 7
 IF theBug = last THEN Main                    ' don't repeat
   last = theBug                               ' save for next cycle

Bug_On:
 RANDOM lottery
 stpSize = lottery // 8 + 1                    ' randomize loop speed
 FOR level = 0 TO 255 STEP stpSize             ' brighten
   PWM theBug, level, 1
 NEXT
 HIGH theBug

On_Time:
 RANDOM lottery
 delay = lottery // 151 + 50                   ' 150 to 300 ms
 PAUSE delay

Bug_Off:
 RANDOM lottery
 stpSize = lottery // stpSize + 1              ' off no slower than on
 FOR level = 255 TO 0 STEP -stpSize
   PWM theBug, level, 1
 NEXT
 LOW theBug

Off_Time:
 RANDOM lottery
 delay = lottery // 250 + 500
 PAUSE delay
 GOTO Main

' -------------------------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

gravediggergreg

WOW...  25 minutes from my post to your solutions, Dominos cant even get me a pizza that quick.   Great idea about the count down, if there was a problem i would know which wire/bulb to work with instead of trying to work them all.  will clearly allow me to trouble shoot during setup if something goes wrong. 

quick youtube of it running.  (ver2) for previous poster

http://www.youtube.com/watch?v=YdujxiD0AZ8