May 01, 2024, 05:47:42 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.


Fireflies

Started by JonnyMac, March 27, 2007, 04:15:22 PM

Previous topic - Next topic

JonnyMac

March 27, 2007, 04:15:22 PM Last Edit: March 28, 2007, 08:28:01 AM by JonnyMac
With your Prop-1 and a handful of grain-of-wheat lamps you can have very natural fireflies.  Just hang the lamps so that they're affected by any breeze.  The program keeps track of which "fly" lit up in each cycle so that the same fly doesn't light twice in a row or again until all have lit.

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


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


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


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


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


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

SYMBOL  theBug          = B2                    ' selected output
SYMBOL  level           = B3                    ' brightness level
SYMBOL  mask            = B4                    ' position mask
SYMBOL  lit             = B5                    ' lit this cycle
SYMBOL  check           = B6                    ' test result
SYMBOL  delay           = W4                    ' timing delay
SYMBOL  lottery         = W5                    ' random value


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

Reset:
  lit = %00000000                               ' reset all flies


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

Main:
  RANDOM lottery                                ' stir random value
  theBug = lottery // 8                         ' select pin 0..7
  READ theBug, mask                             ' get position mask
  check = mask & lit                            ' test this position
  IF check > 0 THEN Main                        ' if not zero, try again
    lit = lit | mask                            ' mark this position

Bug_On:
  FOR level = 0 TO 255 STEP 5                   ' ramp on
    PWM theBug, level, 1
  NEXT
  HIGH theBug

Bug_Hold:
  RANDOM lottery
  delay = lottery // 750 + 250
  PAUSE delay                                   ' wait 0.25 to 1 secs

Bug_Off:
  FOR level = 255 TO 0 STEP -5                  ' ramp down
    PWM theBug, level, 2                        ' a little slowly
  NEXT

Inter_Bug_Delay:
  RANDOM lottery
  delay = lottery // 250 + 250
  PAUSE delay                                   ' wait 0.25 to 0.5 secs

  IF lit = %11111111 THEN Reset                 ' all bugs lit this cycle?
    GOTO Main                                   ' no, keep going


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


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


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

Bit_Masks:
  EEPROM (%00000001, %00000010, %00000100, %00001000)
  EEPROM (%00010000, %00100000, %01000000, %10000000)
Jon McPhalen
EFX-TEK Hollywood Office