Shop OBEX P1 Docs P2 Docs Learn Events
Smooth PWM Transition for LEDs — Parallax Forums

Smooth PWM Transition for LEDs

danny270danny270 Posts: 13
edited 2009-03-26 20:42 in General Discussion
Hello all!
·· I am using PWMLEDs by JohnnyMac to control my RGB led and want to get a smooth transition from one color to the other.·The·program turns off each color at end of pwm.·A section of the program code is shown below:
···FOR brightness = 0 to 254
···· level1 = brightness
···· DELAY_MS 20
···NEXT
·· FOR brightness = 255 to 0 STEP -1···· 'I adjusted this·to 255 to 20 STEP -1
··· level1 = brightness
··· DELAY_MS 20
·· NEXT
Adjustment made a smooth transition from color to color, however, because the step was not all the way to 0, it did not turn the led completely off, thus I donot get a pure color. I added an extra IF-ENDIF statement to completely turn off the LED but the action was not pleasant. While the current LED increases in brightness,·one can see the abrupt turning off of the previous LED.
·· I would appreciate suggestions to achieve·smooth transition from color to color with 1st LED fading out completely while the 2nd LED fades in with no complete blackout during the transition.
My advance thanks.
Danny

Comments

  • BeanBean Posts: 8,129
    edited 2009-03-26 13:49
    Danny,
    · You'll need to adjust the next level up at the same time you are adjusting the previous level down.

    Try this:
    FOR brightness = 0 to 254 
      level1 = brightness
      DELAY_MS 20
    NEXT
     
    FOR brightness = 255 to 0 STEP -1
      level1 = brightness
      IF brightness < 20 THEN
        level2 = 20 - brightness
      ENDIF
      DELAY_MS 20
    NEXT
     
    FOR brightness = 21 to 254
      level2 = brightness
      DELAY_MS 20
    NEXT
    
    


    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...



    Post Edited (Bean (Hitt Consulting)) : 3/26/2009 3:25:44 PM GMT
  • danny270danny270 Posts: 13
    edited 2009-03-26 14:28
    Bean,

    Thanks for the fast reply.

    Tried it but upon compile, gave me error: "invalid number of parameters" , yellowing out line "if brightness < 20".

    Danny
  • danny270danny270 Posts: 13
    edited 2009-03-26 14:39
    Bean,

    Caught it. Forgot the "then". Will continue to work on finetuning it until desired transition is reached.

    Danny



  • danny270danny270 Posts: 13
    edited 2009-03-26 15:03
    Bean,

    Working perfectly now! If fine with you, I like to send you one of my 10W RGBA in MCPCB board. If you PM me your address, I'll mail it to you.

    Thanks again. And thanks to JonnyMac as well.

    Danny
  • BeanBean Posts: 8,129
    edited 2009-03-26 15:25
    Danny,
    Oops. Yeah I missed the "THEN". I went back and fixed it.

    I'll send you my mailing address, but there is no need for gifts unless REALLY want to.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...

    ·
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-03-26 20:12
    I'm doing a lot or RGB stuff this weekend with an SX design I did for another company.... fun, too! One controller sets the color and then sends that in a packet to others on an RS-485 buss so that they "move" in sync.
  • danny270danny270 Posts: 13
    edited 2009-03-26 20:42
    JonnyMac,

    You deserve one of my RGBA as well. Would you like me to mail you one also? If so, PM me your mailing address.

    Danny
Sign In or Register to comment.