Go Down

Topic: Threaded (non-blocking) RGB LED crossfade - examples? (Read 1 time) previous topic - next topic

roypardi

HI - I've seen lots of great examples for working with color fades on RGB LEDs but they all use a tight loop with a delay() controlling duration. I need to control a number of LEDs and have each of them transitioning concurrently. I'm looking at using the Penner easing functions as a starting point but I am wondering if this wheel has already been invented (threaded LED control on Arduino)?

I'm using ShiftBrites - so that adds a little.... complexity.

Cheers, and thanks for any tips.





Magician

Look into :  Examples/Digital/BlinkWithoutDelay - not blocking , still one thread.

AndrewStone

I'm not sure if "easing" is really that noticeable in LEDs vs simple linear, but give it a try and tell us what you find!
But definitely you'll want to remember that the eye's view of brightness is logarithmic against actual energy and compensate for that.  Otherwise the rate of change of a LED going from dark to bright will seem to slow down as it gets brighter.

Actual threading is going to be a bit hard on an Arduino, I did not think that a thread library existed... but you never know its a big world!  Send me a link if you have actually used threading!

I would use an object that tracks each intensity and destination intensity.  And include a "next" call to update to the next intensity (for speed use Bresenham's line drawing alg, not typical high school algebra).  Then loop over each object calling "next".  Hook this loop into the timer if you want it to happen in the background.

There is code that does a lot of this here http://code.google.com/p/arduino-m5451-current-driver/source/browse/trunk/latest/apps/suntree_nightlight/suntree_nightlight.pde.  Look at the RgbFader class.  You'll have to adapt to shift-brite though.

Cheers!
Andrew
www.toastedcircuits.com: Lightuino LED driver
http://www.toastedcircuits.com Lightuino LED driver: 16 sources, 70 sinks, remote controlled.  Also high powered LED drivers.

Go Up