HowTo-Color (8) / Hacking Electronics / Simon Monk / 236-3 / Chapter 6
142
Hacking Electronics
How to Charlieplex LEDs An Arduino only has so many IO pins, so when looking to minimize the number of pins used to display a matrix of LEDs, an interesting technique called Charlieplexing can be used. The name comes from the inventor Charlie Allen at the company Maxim, and the technique takes advantage of the feature of Arduino and other microcontroller IO pins that allows them to be changed from outputs to inputs while a sketch is running. Figure 6-32 shows the arrangement for controlling LED six LEDs with three pins. Table 6-2 shows how the pins should be set to light A a particular LED. B The number of LEDs that can be controlled per C microcontroller pin is given by the following formula: LEDs = n2 – n
Pin 1
Pin 2
Pin 3
High
Low
Input
Low
High
Input
Input
High
Low
D
Input
Low
High
E
High
Input
Low
F
Low
Input
High
So, if we use four pins, we can have 16 – 4 or 12 TABLE 6-2 LEDs, and 10 pins would give us a massive 90 LEDs, but an awful lot of wiring to do. There are, however, problems with scaling Charlieplexing up, not the least of which is that the refresh rate needs to be fast enough to fool the eye, and a large number of pins will need a lot of sequence steps to energize all the LEDs that need energizing in a refresh cycle. This will also result in the LEDs becoming dim because their duty cycle will be low. You can compensate for this to some extent by increasing the current through the LEDs, which will cope with fairly large peak currents for a small duration. This does lead to the problem that
06-ch06.indd 142
Charlieplexing
Figure 6-32 Charlieplexing LEDs
1/2/13 11:56 AM