November 24, 2024, 01:15:26 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.


Random pop up program help

Started by hauntcast, August 17, 2016, 07:09:34 AM

Previous topic - Next topic

hauntcast

I have a DC Props light lifter pneumatic pop up prop and I need a prop-1 program to make it pop up randomly 1 min, 1 min 30 sec and 2 min without a trigger. Please help me Obi Wan.

JonnyMac

How about if I write a program that will make the pop-up activate randomly with an interval of 1 to 2 minutes, with one-second resolution? And how about if I add a trigger input that allows you to make the pop-up activate early should you want a manual scare?

The question becomes... is the pop-up time random, or fixed? In either case, I need information on the pop-up behavior to finish the code.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Here's a starter program with a fixed pop-up time (2s, set by a constant).  Programs are like recipes... they're infinitely flexible.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  PopUp           = PIN0


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  IsUp            = 1                     ' active-high I/O
SYMBOL  IsDown          = 0

SYMBOL  PopTime         = 2000                  ' 2-second pop


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

SYMBOL  delay           = B2                    ' for timing loop
SYMBOL  idx             = B3                    ' debounce loop control
SYMBOL  tPress          = B4                    ' time of trigger press

SYMBOL  lottery         = W5                    ' random #
SYMBOL   lottoLo        =  B10
SYMBOL   lottoHi        =  B11


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

Power_Up:
  READ 0, LottoLo                               ' seed randomizer
  READ 1, LottoHi

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00000001                              ' P0 is output


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

Main:
  RANDOM lottery
  delay = lottery // 61 + 60                    ' delay 60 to 120 seconds

Run_Delay:
  FOR idx = 1 TO 100                            ' 100 x 10ms = 1s
    PAUSE 10
    tPress = tPress + 10 * Trigger              ' update trigger timing
    IF tPress >= 100 THEN Pop_Now               ' manual trigger?
  NEXT
  delay = delay - 1                             ' decrement delay
  IF delay > 0 THEN Run_Delay                   ' still running?

Pop_Now:
  PopUp = IsUp
  PAUSE PopTime
  PopUp = IsDown

  WRITE 0, LottoLo                              ' save random seed
  WRITE 1, LottoHi

  GOTO Reset


' -----[ User Data ]-------------------------------------------------------

Lotto_Seed:
  EEPROM (10, 31)
Jon McPhalen
EFX-TEK Hollywood Office

hauntcast

I don't want a trigger. I just need it to pop up between 1 to 2 minute intervals, randomly if possible once powered on. Thank you for your help.

bsnut

August 18, 2016, 12:06:15 AM #4 Last Edit: August 18, 2016, 12:51:59 AM by bsnut
Jon's code will do what you are wanting to do if the manual trigger isn't connected or pushed. You can change how long the prop is to run with this line of code in above program.

SYMBOL  PopTime         = 2000                  ' 2-second pop

BTW, the manual trigger is a added feature that doesn't need to be code later if you change your mind, all you have to do is connect a trigger to that I/O pin and you are ready to go.
William Stefan
The Basic Stamp Nut

JonnyMac

August 18, 2016, 10:10:36 AM #5 Last Edit: August 18, 2016, 10:12:36 AM by JonnyMac
Key part of my response that was glossed over:

a trigger input that allows you to make the pop-up activate early should you want a manual scare

You may not want to use a manual trigger with your prop, but you'll want one when testing and making code changes. As I and William pointed out, the trigger is an OPTION, not a REQUIREMENT.
Jon McPhalen
EFX-TEK Hollywood Office

hauntcast

Thanks for the help. I hope my last reply wasn't misinterpreted, as I being bitchy about not wanting a trigger I was just clarifying. I did gloss over your response.

JonnyMac

No worries. We will often give more than one asks for, because we've done this long enough that we know what people come back with later. Anyway, have fun with the code and let us know if we can help you make adjustments.
Jon McPhalen
EFX-TEK Hollywood Office