November 25, 2024, 04:03:31 AM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


New Fading LEDS

Started by imagineerdan, December 03, 2007, 11:07:27 AM

Previous topic - Next topic

imagineerdan

The below code works well, I was wondering what it would take to
have the LEDS on high then fade them off one by one sequentially, in
the same kind of code, ie with the random off times. - Thanks :)


Chaser:
  FOR theLamp = 0 TO 13                         ' loop through outputs
    RANDOM lottery
    speed = lottery // 6 + 5
    FOR level = 255 TO 0 STEP 8                 ' bright to dark
      PWM theLamp, level, speed
    NEXT
  NEXT
  GOTO Chaser








JonnyMac

December 03, 2007, 11:13:53 AM #1 Last Edit: December 03, 2007, 11:15:44 AM by JonnyMac
You just need to start with the LEDs on, like this:

Setup:
  DIRS = %0011111111111111                      ' P0..P13 are outputs

Chaser:
  OUTS = %0011111111111111                      ' all on
  PAUSE 50
  FOR theLamp = 0 TO 13                         ' loop through outputs
    RANDOM lottery
    speed = lottery // 6 + 5
    FOR level = 255 TO 0 STEP 8                 ' bright to dark
      PWM theLamp, level, speed
    NEXT
  NEXT
  GOTO Chaser


I added a very short delay for effect -- you may want to remove that.
Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

Is there a way on the BS2 to fade the lights, like a ramp or a wipe similar to the Moodskull code for the BS1 but in a sequential fashion? I though want them to do this in the reverse to ramp off in the same way the moodscul ramps them on?

JonnyMac

Sure... the code I just posted does that.  You might want to slow things down, though, and if you want to reverse the order, change the starting value of the outer FOR-NEXT loop to 13, and the ending value to zero.
Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

When I use the code the LEDS do not start all on, then fade off sequentially, what do think I did wrong?

Setup:
  DIRS = %0011111111111111                      ' P0..P13 are outputs

Chaser:

  PAUSE 50
  FOR theLamp = 0 TO 13                         ' loop through outputs
    RANDOM lottery
    speed = lottery // 6 + 5
    FOR level = 255 TO 0 STEP 8                 ' bright to dark
      PWM theLamp, level, speed
    NEXT
  NEXT
  GOTO Chaser


JonnyMac

Whoops, my fault.  There is a little detail about PWM that's critical here: it leaves the I/O in an input mode when finished (because it's often used to charge RC circuits; input mode prevents draining the RC between PWM calls).  If you add a LOW command after the loop it all works.

This is code that is running on my system -- I know this works:

Reset:
  DIRS = %0011111111111111                      ' P0..P13 are outputs

Main:
  OUTS = %0011111111111111                      ' all on
  PAUSE 50

Chaser:
  FOR theLamp = 0 TO 13                         ' loop through outputs
    RANDOM lottery
    speed = lottery // 6 + 5
    FOR level = 255 TO 0 STEP 8                 ' bright to dark
      PWM theLamp, level, speed
    NEXT
    LOW theLamp
  NEXT
  GOTO Main
Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

Works Beautifully!, thanks for the excellent help Jon!