Smooth PWM Transition for LEDs
danny270
Posts: 13
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
·· 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
doc
52K
Comments
· You'll need to adjust the next level up at the same time you are adjusting the previous level down.
Try this:
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
Thanks for the fast reply.
Tried it but upon compile, gave me error: "invalid number of parameters" , yellowing out line "if brightness < 20".
Danny
Caught it. Forgot the "then". Will continue to work on finetuning it until desired transition is reached.
Danny
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
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...
·
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