-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Arduino library to control any number of LEDs on any available pins using 10-bit PWM with linear adjustment using CIE 1931 curves.
The library allows any number of pins, as many as the corresponding Atmel ATMega processor has, to be defined as 10-bit PWM output pins. It supports setting PWM values from 0-1023 (where 0 is "OFF" and 1023 is 100% "ON") on any pin along with calls that automate "fading" - e.g. set the pin to "OFF" and fade to "FULL" linearly over 2 seconds. The details of how to setup the library along with all of the publicly available methods can be found on the INA wiki pages.
Fading a LED so that it looks both smooth and linear requires a bit of work, including appling CIE 1931 Compensation. This makes a fade look linear end-to-end, but comes at a cost of reserving 2kB of program memory. The link describes how to free up that memory if linear fading is not required.
Robert Heinlein made the expression TANSTAAFL popular and it certainly applies here - "There ain't no such thing as a free lunch". While certain pins support hardware PWM, they are bound to specific TIMER{n} registers. All of the other pins are relegated to being mere digital pins with only "on" or "off" settings. This library uses the ATMega's TIMER1 and creates an interrupt in the background which then takes care of setting the pin to "on" and "off" in the background - quickly enough so that it is effectively a PWM signal. But doing this via interrupts means that CPU cycles are being used and these affect how many CPU cycles are left for the currently active sketch. The more LEDs defined in the library and the higher the defined interrupt rate the less cycles are left over for the sketch. A detailed description of the performance hit incurred with various numbers of LEDs and at different hertz() settings can be found on CPU Consumption wiki page.
The documentation has been done using Doxygen and can be found at doxygen documentation