ArduinoLibs
|
Charlieplexing is a technique for multiplexing large numbers of LED's on a small number of microcontroller output pins. LED's are arranged in complementary pairs and managed by the Charlieplex class. For this example we are going to use 3 output pins to drive 6 LED's:
The technique can be expanded to even larger numbers of LED's. See the documentation for the Charlieplex class for a description of how to connect up larger numbers of pins in a Charlieplexed arrangement.
The first step is to initialize a Charlieplex object with the output pins it needs to drive:
Then in setup()
we use Charlieplex::setLed() and Charlieplex::setPwmLed() to set three of the six LED's to the desired output values:
Charlieplexing can only light a single LED at a time. It is therefore necessary to constantly scan the entire LED array, alternatively turning LED's on and off. The user's peristence of vision fills in the gaps. To do this, we call Charlieplex::loop():
The downside of Charlieplexing is that when multiple LED's are lit, each LED will appear to be dimmer than if only a single LED was lit. This can be counteracted by using brighter LED's or smaller resistors. The danger with smaller resistors is that if the program crashes or locks up for some reason, a large amount of continuous current could be fed through a single LED and cause it to exceed its maximum rating and burn out.
The full source code for the example follows:
A more complex example that performs a LED chase over the 6 LED's follows: