Monday, 27 October 2008

Digital LED brightness control

While working on the encoder-with-led-ring concept I figured it might be cool if I could control the brightness of each LED individually. For example, the led ring brightness could increase while turning a specific encoder, or the leds be brighter the further 'up' the ring they are.

I already intend to time multiplex the diodes to get away with a single resistor between 16 leds, so I thought, why not try using pulse width modulation (is that the correct term?) to control the LED brightness in software?

I just did a proof of concept, and although the picture below doesn't do the result justice, you can clearly see that it works :-D

the code for the test is dirt simple. Each led down the row is turned on twice as long as the previous one, exponentially increasing the time (but not the brightness):

Pseudo code of the program is as follows:

PORTD = 1;
PORTD = 2;
PORTD = 4;
PORTD = 8;
PORTD = 16;
PORTD = 32;
PORTD = 64;
PORTD = 128;

No comments: