November 23, 2024, 02:06:36 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.


Candle loop and glowing loop

Started by imagineerdan, October 22, 2008, 03:38:26 PM

Previous topic - Next topic

imagineerdan

I have been trying to modify, with no avail the candle flicker code (modified version attached) to pwm pin 6 on and off like the mac computer sleep led, then as long as pin 7 is pushed for pin0- pin5 flicker irratically like the candle flicker.

This is for a halloween costume and I will be glad to post pics when Im through!

JonnyMac

October 22, 2008, 05:26:14 PM #1 Last Edit: October 22, 2008, 05:34:39 PM by JonnyMac
So P6 pulsates and the "candles" are off until P7 goes high; when P7 is high then the pulsating stops and the candles go on?

If that's the case, then this program should be close.  I don't have a Mac and have never used one, so I don't know what you mean by the Mac sleep LED.  The "pulsar" LED in this program brightens and dims until the trigger button is pressed.  As long as you hold the trigger button the candles will flicker.

' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 22 OCT 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN7                  ' SETUP = DN
SYMBOL  Pulsar          = 6
SYMBOL  Wicks           = PINS

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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  flags           = B0
SYMBOL   direction      =  BIT0

SYMBOL  timer           = B2
SYMBOL  level           = B3
SYMBOL  idx             = B4
SYMBOL  delay           = B5

SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %01111111                              ' set outputs


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

Main:
  level = 0
  direction = 0
  timer = 0

Check_Trigger:
  PWM Pulsar, level, 1
  timer = timer + 5 * Trigger
  IF timer = 100 THEN Flicker
  IF direction = 1 THEN Check_Dim

Check_Bright:
  level = level + 1
  IF level < 255 THEN Check_Trigger
    direction = 1
    GOTO Check_Trigger

Check_Dim:
  level = level - 1
  IF level > 0 THEN Check_Trigger
    direction = 0
    GOTO Check_Trigger


Flicker:
  FOR idx = 1 TO 3
    RANDOM lottery                              ' big stir
  NEXT
  Wicks = lottery & %00111111                   ' update wicks

  RANDOM lottery
  delay = lottery // 51 + 25                    ' random, 25 to 75ms
  PAUSE delay

  IF Trigger = IsOn THEN Flicker                ' still active?
    Wicks = %00000000                           ' no, clear wicks
    GOTO Main                                   ' back to pulsar


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


' -------------------------------------------------------------------------


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

imagineerdan

That works perfectly, I will post images/video when I get it finished, thanks Jon!

JonnyMac

Please do! -- we love to see our friends' work in action.
Jon McPhalen
EFX-TEK Hollywood Office