November 15, 2024, 05:57:07 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.


Wind and Weather House Effect

Started by flashular, September 12, 2007, 11:36:15 AM

Previous topic - Next topic

flashular

September 12, 2007, 11:36:15 AM Last Edit: October 02, 2007, 08:15:14 AM by flashular
I've got a simple BS1 program that might be of interest to someone out there.

I'm using the prop1 married to a quad triac board that simulates room flicker (like candles), random lightning strikes , thunder (via onboard sound), and wind (via a fan). I also use a motion sensor PIR to beef up the lightning when someone is near and to turn the fan/off appropriately.

The way I'm using this  is to provide a room with flickering light using a cheap orange light string. One in a while the program flashes a bright light (100W clear bulb) with accompanying thunder sound (using amplified PC speakers). When a human is detected the wind comes up (via a 12" portable fan) and the lightning starts flashing at a faster rate. Once the human has left the system settles back into the flicker with occasional lightning.

If anyone is interested in the hardware side of things check here:  http://67.131.73.173/StupidlySimple/index.htm.

Here is the program (sorry for the tabs):



                                     ' {$STAMP BS1}
' {$PBASIC 1.0}
' -------------------------------------------------------------------------------------
' spooky weather
' -------------------------------------------------------------------------------------
'
' PIN 0 - sound     OUT - thunder sound
' PIN 1 - flicker   OUT - flickering ambient lights
' PIN 2 - lightning OUT - quick flash when lightning strikes
' PIN 3 - movement  OUT - monitor for motion sensor
' PIN 4 - wind      OUT - turns on the wind in presence of humans
' PIN 7 - motion    IN  - PIR sensor to test for humans nearby
'
' ------------------------------------------------------------------------------------

' pin assignments

SYMBOL  Speaker      =    0               ' pin 0 - audio output
SYMBOL  Flicker      = PIN1        ' pin 1 - ambient flickering light out
SYMBOL  Lightning    = PIN2              ' pin 2 - light strobe out
SYMBOL  MovementOut  = PIN3        ' pin 3 - active when movement is detected
SYMBOL  WindOut      = PIN4      ' pin 4 - wind when humans present
SYMBOL  MotionSensor = PIN7     ' pin 7 - attach PIR sensor on 3 pin jumper

' variables and constants

SYMBOL  RandVal      = W0                 ' random number generator
SYMBOL  ThunderFrq   = W1               ' lightning sound frequency
SYMBOL  FlashThresh  = W2                          ' current threshold for lightning flash
SYMBOL  WindVal      = W4        ' curent wind countdown timer
SYMBOL  HumanFound   = W5    ' true if motion sensor finds anything
SYMBOL  AloneThresh  = 65400          ' thresholed for lightning when nobody nearby
SYMBOL  HumanThresh  = 64000   ' threshold for lightning when humans nearby

' set up system
' -----------------------------------------------------------------------------------

Startup:

DIRS  = %01111111                  ' configure inputs/outputs ( only PIN7 input )
PINS  = %00000000                  ' default states to zero

HumanFound =  0    ' zero sensor status
WindVal    =  0          ' zero wind timer

' main program loop
' ----------------------------------------------------------------------------------

Update:

  GOSUB UpdateMotion ' update the motion sensor
  GOSUB UpdateWind ' update wind state
  GOSUB UpdateFlicker   ' update the flickering lights
  GOSUB UpdateLightning ' update the ligtning and thunder
  GOSUB UpdateThunder        ' update the thunder sound

  GOTO Update     ' run this loop forever


' update the motion sensor state
' ----------------------------------------------------------------------------------


UpdateMotion:

HumanFound  = MotionSensor      ' sample the motion sensor
MovementOut = HumanFound               ' copy state to the movement light

RETURN


' update the wind model
' ----------------------------------------------------------------------------------

UpdateWind:

  IF HumanFound = 0 THEN  SkipWindStart          ' is motion detected?
  WindVal = 255       ' start the wind timer
  SkipWindStart:        ' end if

  IF WindVal = 0 THEN SkipWindTimer     ' is the timer active?
  WindVal = WindVal - 1     ' decrement wind timer

    IF WindVal > 0 THEN  SkipWindReset
    WindOut = 0
      SkipWindReset:

  SkipWindTimer:      ' end if

' WindOut = 0                                                           ' default wind off
  IF WindVal = 0 THEN SkipWindActivate           ' if wind timer active
  WindOut = 1      ' activate wind
  SkipWindActivate:

' DEBUG WindVal , WindOut

RETURN

' update the flickering background lights
' ----------------------------------------------------------------------------------

UpdateFlicker:

  RANDOM RandVal                  ' get a new random value

  IF Lightning = 1 THEN SkipFlicker      ' is flicker active?
  Flicker = RandVal               ' put the random value to the flicker lights
  SkipFlicker:                                                           ' end if

RETURN


' update lightning trigger
' ----------------------------------------------------------------------------------

UpdateLightning:


  IF ThunderFrq > 250 THEN SkipRelease        ' is lightning done?
  Lightning = 0                                  ' turn off the flash
  SkipRelease:                                                         ' end if


  FlashThresh = AloneThresh       ' assume we are alone to set threshold
  IF HumanFound = 0 THEN SkipHumanFlash              ' is motion detected?
  FlashThresh = HumanThresh                                   ' set human flash threshold
  SkipHumanFlash:            ' end if


IF RandVal < FlashThresh THEN SkipTrigger          ' is new lightning ready?
  Flicker = 0                  ' turn off the flickering lights
  Lightning = 1                          ' turn on the lightning flash
  ThunderFrq = 255   ' turn on the thunder
  SkipTrigger:                                                   ' end if

RETURN


  ' update thunder sound
  ' --------------------------------------------------------------------------------

UpdateThunder:

  IF ThunderFrq <= 128 THEN SkipThunder       ' is thunder is active?
  ThunderFrq = ThunderFrq - 1             ' drop the pitch
  SOUND Speaker, (ThunderFrq, 2 )                            ' make the thunder sound
  SkipThunder:                           ' end if

RETURN




gadget-evilusions

I would be interested in seeing your hardware setup!
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

livinlowe

Me too! This looks like a cool halloween application! Good Job! 8)
Shawn
Scaring someone with a prop you built -- priceless!

dacostasr


flashular

September 28, 2007, 11:06:06 AM #4 Last Edit: September 28, 2007, 11:35:02 AM by flashular
Ok, I did a quick writeup which you can find on my website here:

http://67.131.73.173/StupidlySimple/index.htm


I also posted another application I did with it here:

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


Hope that helps!