We recently completed a prototype that called for expressive LED lighting. The team wanted the device to have a personality; simply turning LEDs on or off wasn’t enough. We wanted LED’s to “wake up” slowly, gently turn off, and “breathe” (continually fade brightness up and down) with variable rhythm. More importantly, these LED animations needed happen at the same time. This requires the LED software to “multitask.” I used Arduino because it reduces complexity and development time.
There is no native support for multitasking in Arduino, so I developed a custom solution. Each LED output would be updated in sequence every time around the “loop.” For example, if there are three LEDs, LED1 updates, then LED2, then LED3. The software loops and the LEDs are updated again. Each time an LED is updated, the Arduino software calculates the LED output brightness based on the desired animation behavior.
A software LED description (C++ class) of LED behaviors and LED attributes called LEDController was created. Each real LED is represented in Arduino software as an LEDController software object. Every time an LED is updated, its LEDController object calculates its brightness, then sends the brightness value to the Arduino (PWM) output that drives the LED.
Not much later, a project came along requiring simultaneous animation of 36 LEDs. There aren’t 36 PWM outputs readily available on Arduino, so I used two LED driver ICs (LTC3220), each capable of driving 18 LEDs. An I2C interface was added to the LEDController class so instead of controlling an Arduino PWM output, the brightness value for each LED is sent on the I2C bus to its LED driver IC.
The multitasking approach developed for LEDs can be adapted for other kinds of output devices. For example, the LEDController PWM output could be converted to a reference signal for motor position or velocity control. Imagine controlling a set of motors, or a combination of motors and LEDs. Any project needing to control multiple analog outputs could benefit from this class or adaptations of it. IDEO’er Dave Vondle has verified this class works with the Arduino Mini shield he created. This would be useful if you have a project that requires rechargeable batteries or high power outputs.
I expect to continue to use and adapt LEDController, and I hope you find a use for it as well. If you do, please post it in the comments and show off what you made!