November 23, 2024, 05:36:26 PM

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.


Debouncing PIR while doing a PWM loop on Prop-1

Started by gadget-evilusions, September 25, 2010, 06:04:05 PM

Previous topic - Next topic

gadget-evilusions

This may not be possible, but I figured I would try.

I am attempting to write a program for a Frankenstein lab machine. 

Trigger         = PIN6                 
Audio           = PIN5                 
                   
Led3            = PIN2                     
Led2            = PIN1                     
Led1            = PIN0

I have the after the trigger part of the program done, and triggering the audio is not a problem. Where I am having difficulty is doing anything in the prop's idle state while it's sitting around waiting for a trigger. My goal was to start with led1, led2, and led3 on, do a PWM loop to dim led1, led2, and led3 from full bright to full dim, then turn back on(not pwm) full bright, in a random order, while debouncing the input. After a valid input is seen, it would continue with the rest of my pwm loops and audio triggerings (that part of my program is already working). Is something like this possible or am I asking too much?


     
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

You're not asking for too much, you're just asking for too much from the Prop-1.  You would need a Prop-SX to do what you're looking for and the code wouldn't be very easy.

Not to worry, though, with a BOC (big ol' capacitor) connected between V+ and your LED output channels you can get the same effect (it would work like a big version of the wick LED).  The guys in the engineering department at Disneyland did this for the pumpking ornaments that are hanging on the Christmas tree in the Haunted Mansion (it's in the dining room).  On of the gifts under the tree is a cleverly-hidden control box with 8 or 10 Prop-1s.
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

I will make that work then.

I need two code snippets then if you have time.

First could you show me how to just turn on and off the 3 outputs while debouncing the pir?

Secondly could you show me how to do a PWM loop that would randomize which output it's raising or lowering?

This is the style loop I am use too:

FOR pinNum = 0 TO 2
   FOR  level = 0 TO 255 STEP 2
      PWM pinNum, level, 2
    NEXT
    HIGH pinNum
  NEXT

That would allow me to just blink the outputs during the debounce, and them PWM loop them after the sensor is triggered and I think I would be good.

Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

Here's something to experiment with.

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


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN


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

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

SYMBOL  Baud            = OT2400


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

SYMBOL  idx             = B2
SYMBOL  timer           = B3


SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00000111                              ' make P0-P2 outputs


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

Main:
  PINS = %00000001                              ' start with P0

Check_Trigger:
  timer = 0
  FOR idx = 1 TO 25                             ' 250ms debounce check
    RANDOM lottery
    PAUSE 10
    timer = timer + 10 * Trigger
  NEXT

  IF timer > 220 THEN Run_Prop                  ' run if active trigger

  IF PINS = %00000100 THEN Main                 ' reset if on last
    PINS = PINS * 2                             ' move to next light
    GOTO Check_Trigger

Run_Prop:
  PINS = %00000000
  RANDOM lottery
  idx = lottery // 3                            ' idx is 0 to 2
  FOR timer = 0 TO 255                          ' fade up
    PWM idx, timer, 2
  NEXT
  HIGH idx                                      ' hold high
  PAUSE 1000
  PINS = %00000000
  PAUSE 250
  GOTO Main


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


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

gadget-evilusions

Perfect. Thank you very much. That helped me create almost exactly what I was after in the first place.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components