November 23, 2024, 01:42:42 AM

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.


Coal Trigger Question

Started by imagineerdan, December 19, 2011, 12:36:26 PM

Previous topic - Next topic

imagineerdan

I am creating a prop of logs and coals I want to be able to trigger on and off. I created the below code but cant figure out how to get it to flicker and do its routine when pin7 is contact closed and to stop flickering when pin7 is off? How can I make this work? thanks!!

' {$STAMP BS1}

' Fading lights for PIN0-PIN7

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

SYMBOL  Lamp7           = PIN7
SYMBOL  Lamp6           = PIN6
SYMBOL  Lamp5           = PIN5
SYMBOL  Lamp4           = PIN4
SYMBOL  Lamp3           = PIN3
SYMBOL  Lamp2           = PIN2
SYMBOL  Lamp1           = PIN1
SYMBOL  Lamp0           = PIN0


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


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

SYMBOL  theLamp         = B2                    ' lamp to brighten or dim
SYMBOL  last            = B3                    ' last lamp adjusted
SYMBOL  level           = B4                    ' output level (for PWM)
SYMBOL  mask            = B5                    ' bit mask test
SYMBOL  temp            = B6
SYMBOL  speed           = B7                    ' adjustment speed
SYMBOL  lottery         = W5                    ' random value


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

Reset:
  DIRS = %01111111                              ' P0 - P7 are outs
  lottery = 1031                                ' seed random value


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


Start:

IF PIN7 = 1 THEN Main:

GOTO Start:





Main:
  RANDOM lottery                                ' tumble random value
  theLamp = lottery // 3                        ' select a lamp, 0 - 8 (which pins to flicker)
  IF theLamp = last THEN Main                   ' no repeats
    last = theLamp

  READ theLamp, mask                            ' get bit for that lamp
  temp = PINS & mask                            ' test selected lamp
  IF temp = 0 THEN Brighten

Dim:
  RANDOM lottery
  speed = lottery // 11 + 10                    ' set speed, 10 to 20
  FOR level = 255 TO 70 STEP -speed              ' decrease output level
    PWM theLamp, level, 1
  NEXT
  LOW theLamp                                   ' lamp fully off
  GOTO Main

Brighten:
  RANDOM lottery
  speed = lottery // 11 + 10                    ' set speed, 10 to 20
  FOR level = 70 TO 255 STEP speed               ' increase output level
    PWM theLamp, level, 1
  NEXT
  HIGH theLamp                                  ' lamp fully on
  GOTO Main:

JonnyMac

Before I suggest code, what are you driving on the outputs?  The problem with PWM is that while one pin is being PWM'd, the others are left floating.  Unless you got a big capacitor hanging off that output it will simply go out.  When using the Prop-1 for this kind of display, it's best to use a WickLED-type RC circuit on the output. 
Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

I am using super low current 3mm LEDs with 100uF caps in line with them. Thanks Jon!

JackMan

QuoteI am creating a prop of logs and coals I want to be able to trigger on and off. I created the below code but cant figure out how to get it to flicker and do its routine when pin7 is contact closed and to stop flickering when pin7 is off?

I'm a little confused here, you have a lamp on every PIN so how can PIN7 be a trigger? 

imagineerdan

Im sorry , no I only am using pins 0-2 as outs. pin7 is an in.

JonnyMac

Give this version a try.  Notice the Lamp output definitions -- you cannot use PINx assignments here with the PWM command (I've covered this is a few places in the forums).  Also, this version will ramp up the brightness and then allow the output to decay through the capacitor.  You'll need to tweak the elements in the Brighten section, but this should be close.

BTW, the Haunted Mansion uses custom WickLED circuits and a whole bunch Prop-1 controllers for the pumpkin ornaments that are on the tree in the dinning room scene.

' {$STAMP BS1}

' Fading lights for PIN0-PIN2


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

SYMBOL  Trigger         = PIN7

SYMBOL  Lamp2           = 2
SYMBOL  Lamp1           = 1
SYMBOL  Lamp0           = 0


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


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

SYMBOL  theLamp         = B2                    ' lamp to brighten or dim
SYMBOL  last            = B3                    ' last lamp adjusted
SYMBOL  level           = B4                    ' output level (for PWM)
SYMBOL  speed           = B5                    ' adjustment speed
SYMBOL  lottery         = W5                    ' random value


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

Reset:
  DIRS = %00000111                              ' P0 - P2 are outs

  lottery = 1225                                ' seed random value
  last = 99


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


Main:
  RANDOM lottery
  IF Trigger = IsOff THEN Main                  ' wait for trigger

Set_Lamp:
  RANDOM lottery
  theLamp = lottery // 3                        ' randomize, 0 - 2
  IF theLamp = last THEN Set_Lamp               ' don't repeat
    last = theLamp                              ' save for next

Brighten:
  RANDOM lottery
  speed = lottery // 11 + 10                    ' set speed, 10 to 20
  FOR level = 70 TO 255 STEP speed              ' increase output level
    PWM theLamp, level, 1
  NEXT

  GOTO Main
Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan