The motive behind this article is to introduce Binary Code Modulation to a wider audience. Binary Code Modulation (BCM) is an alternative to Pulse Width Modulation (PWM) when controlling frequency insensitive devices, such as LEDs. Both of these methods are described.
There are other methods of LED dimming available (for example error diffusion), but these are not covered.
Example code is provided for Binary Code Modulation that demonstrates 8 channels of 8-bit (256 values) dimming.
OK, so you're bored with a blinking LED. What about dimming an LED instead?
Voilla, your LED will be dimmer.
Wow, short article!
Oh, hang-on, this article is supposed to cover a little more ground than that... I'll witter on a little longer...
The flippant first example demonstrates that despite controlling the LED in an essentially binary fashion (it is only ever on or off), the human eye can be fooled into believing that the LED is being dimmed. All we need to do is repeatedly turn it on and off at high speed (the minimum rate required is covered under the 'Complications' section).
In that first example, where the LED is on for the same amount of time as off, it has a "duty cycle" of 50%. This simply means that the LED is on for 50% of the time. If we changed the delays so that the LED is off for twice as long as it's on, then it would have a duty cycle of 33%. i.e. It would be on for an average of 33% of the time.
Duty cycle is calculated as;
It is often stated as a percentage, rather than as a fraction.
The eye isn't sensitive to the frequency at which an LED is flashing (again, assuming a minimum flicker rate - see 'Complications'). An LED running at 50% duty cycle on a 1khz frequency will look the same brightness as an LED running at 50% duty cycle on a 15khz frequency. The eye averages the "on"s and "off"s regardless of their precise timing. It doesn't even matter if the pattern of 'on's and 'off's are not regular. It is the average on-time that counts.
e.g. The following three patterns, if repeated rapidly enough, are indistinguishable from each other by eye;
On to the different methods of creating these "dimming" patterns...