November 17, 2024, 11:45:59 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.


Random LED fade

Started by imagineerdan, September 18, 2007, 07:29:11 PM

Previous topic - Next topic

imagineerdan

Hi,

I am trying to get an LED, on a single pin to PWM and ramp up and down at random speeds over and over again, Fast, slow, but not just turn on and off.  How would this code look. Thanks for the help!

JonnyMac

September 18, 2007, 07:43:25 PM #1 Last Edit: September 18, 2007, 10:13:33 PM by JonnyMac
Here's a start -- you'll want to tweak to get the pulsing effect you desire.

' =========================================================================
'
'   File...... Pulsate.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  LED             = 0


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


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

SYMBOL  speed           = B2                    ' sets PWM loop speed
SYMBOL  level           = B3                    ' PWM loop control
SYMBOL  lottery         = W5                    ' random value


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

Reset:


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

Ramp_Up:
  RANDOM lottery                                ' stir random value
  speed = lottery // 5 + 2                      ' make 2 to 6

  FOR level = 0 TO 255 STEP speed               ' make brighter
    PWM LED, level, 1
  NEXT
  HIGH LED

Ramp_Down:
  RANDOM lottery                                ' stir random value
  speed = lottery // 7 + 1                      ' make 1 to 7

  FOR level = 255 TO 0 STEP -speed              ' make dimmer
    PWM LED, level, 1
  NEXT
  LOW LED

  GOTO Ramp_Up


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


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

JonnyMac

Here's one that has more of shimmering output.

' =========================================================================
'
'   File...... Shimmer.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Led             = 0


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

SYMBOL  Cycles          = 2


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

SYMBOL  level           = B10                   ' brightness level
SYMBOL  lottery         = W5                    ' random value


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

Reset:


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

Main:
  RANDOM lottery
  PWM Led, level, Cycles
  GOTO Main


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


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

goober

I want to run about 100 LEDs under a 4' diameter cauldren. I need to have a fading and random sequence to give it a fire look.
Questions: How many LEDs can I run off each out pin? Should I keep half the LEDs on all the time and use a relay with a separate power source? And what controller should I use, prop-2 or prop-sx?

livinlowe

goober-
I believe the max current the uln will allow without burning out is 500 ma (speaking of, Jon - can we get that diagram that shows the max current curve stickied to the top of the prop-1 boards?). So, I don't think your going to get 100 LED's. With ultrabright LED's I don't know that you'd need that many.

If your looking to PWM more than one output of LED's - Prop-SX is the ONLY controller that will do it (the question is a popular one!  ;D )

Hope that helps
Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

It's 500 mA if you're only running one channel -- for safety when running multiple channels we suggest you limit it to under 200. 

An easier solution to the caldron might be the FC-4 and four colored lamps.
Jon McPhalen
EFX-TEK Hollywood Office