May 20, 2024, 07:06:13 AM

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.


Standardized MIB Program

Started by JonnyMac, August 10, 2010, 10:09:13 AM

Previous topic - Next topic

JonnyMac

Well, it's that time of year and the MIB questions have started.  Here's a little MIB program that I whipped up that is based, in part, on the CindyBob MIB project.  The difference is that I use a pneumatic cylinder to move the box instead of cam on a motor; the random pulsing of a cylinder is far more interesting as it is not cyclical in behavior and a cam system is.

There are two light outputs to cause flashing in the box.  The best thing to use (IMHO) is LED automotive replacement bulbs.  They are very bright and only need about 90mA (far less than incandescent lamps).  The lamps are randomly flashed as the box/lid jumps.  By putting one lamp on either side of the box you get apparent movement.

I downloaded the audio from the CindyBox site and noticed that it was horribly clipped (this causes distortion in the audio which gets exacerbated when using an ISD-based player).  I used the "Clip Fix" function of Audacity, pitched it down a bit, and adjusted the timing to 10 seconds.  You can download my updated file by clicking on this link:

MIB Audio

Here's the code (note that timing changes can be adjusted in constants so you don't need to dig into the code):

' =========================================================================
'
'   File...... MIB.BS1
'   Purpose... "Standard" MIB code with variable hold-off and reset delays
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Connections:
'
' P7 -   PropPot in Prop-1 mode for start delay
'        * must remove pin 1 of ULN2803
'        * must remove P7 SETUP jumper
'
' P6 -   PropPot in Prop-1 mode for reset delay
'        * must remove pin 2 of ULN2803
'        * must remove P6 SETUP jumper
'
' P5 -   Active-high trigger input
'        * Parallax PIR
'        * N.O. button/mat switch between P5.W and P5.R
'
' OUT4 - Pulse out to audio player
'        * use OUT4/GND to send start pulse to AP-8 (P input)
'        * use V+/OUT4 to send 12v pulse to AP-16 or Cowlacious
'
' OUT3 - Control to 12v light
'        * suggest 12v LED automotive brake light/turn light
'
' OUT2 - Control to 12v light
'        * suggest 12v LED automotive brake light/turn light
'
' OUT1 - To cyclinder that controls lid or box jumping
'
' OUT0 - To relay that controls fogger remove
'        * Be VERY CAREFUL with fogger remote wiring


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


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

SYMBOL  StartPot        = PIN7                  ' No SETUP, No ULN
SYMBOL  ResetPot        = PIN6                  ' No SETUP, No ULN
SYMBOL  Trigger         = PIN5                  ' ULN is pull-down
SYMBOL  Audio           = PIN4                  ' pulsed output
SYMBOL  Light2          = PIN3                  ' 12v LED brake light
SYMBOL  Light1          = PIN2                  ' 12v LED brake light
SYMBOL  Box             = PIN1                  ' to cylinder
SYMBOL  Fogger          = PIN0                  ' to relay for fogger


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

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

SYMBOL  FogRun          =  2000                 ' 2 seconds
SYMBOL  AudioPulse      =   250                 ' 1/4s pulse for player
SYMBOL  AudioRun        = 10000                 ' audio is 10s

SYMBOL  MinJump         =   100                 ' timing for lid/box jumps
SYMBOL  MaxJump         =   250


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

SYMBOL  flash           = B2                    ' for light flashing

SYMBOL  timer           = W3                    ' event timer
SYMBOL  delay           = W4                    ' run delay
SYMBOL  lottery         = W5                    ' random #


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00001111                              ' make P0-P3 outputs

Reset_Delay:
  POT ResetPot, 100, timer                      ' read reset delay pot
  timer = timer * 120                           ' make 0 to ~30s
  PAUSE timer


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery                                ' stir random #
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

Start_Delay:
  POT StartPot, 100, timer                      ' read start hold-off
  timer = timer * 40                            ' make 0 to ~10s
  PAUSE timer

Start_Fog:
  Fogger = IsOn
  PAUSE FogRun
  Fogger = IsOff

Start_Audio:
  Audio = IsOn
  PAUSE AudioPulse
  Audio = IsOff

  timer = 0                                     ' clear event timer

Thrash:
  RANDOM lottery                                ' re-stir
  delay = MaxJump - MinJump + 1                 ' get span
  delay = lottery // delay + MinJump            ' calc jump timing
  Box = IsOn - Box                              ' toggle cylinder

  flash = lottery & %00001100                   ' isolate lights
  PINS = PINS &/ %00001100 | flash              ' update light outputs

  PAUSE delay                                   ' hold
  timer = timer + delay                         ' update run timer
  IF timer < AudioRun THEN Thrash               ' if not done, go again
    GOTO Reset


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


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