There are several methods to drive LEDs using a microcontroller. The easiest method is just connecting all LEDs to an own pin on the microcontroller. Say you have \$n\$ pins available, you'll be able to drive \$n\$ pins.
However, there are different methods to drive LEDs as well:
- A diode matrix:
Divide the pins into two sets: one for current source, one for current sink. Set the sources to0
by default and the sinks to1
. Now, to light one LED, set the connected source to1
and the sink to0
. Do this for all LEDs, after each other. - Charlieplexing:
With Charlieplexing, you set the unused pins to input, giving those a high-impedance state, 'disconnecting' them from the circuit.
What I'm looking for now is an overview of these methods to drive LEDs (and other much-used methods to drive LEDs, in a more efficient way than the 1:1-method described before, if they are noteworthy). What I need for every method is two calculations:
- Given \$n\$ pins, what would be the maximum amount of LEDs to drive?
- When you need \$n\$ LEDs, how many pins will you have to use as a minimum?