A while back I wrote an article for MAKE's blog about Charlieplexing LEDs with an AVR or Arduino. I just wanted to drop this quick update on how to 'plex 20 LEDs. I've now had TWO different people ask about doing more than 12 LEDs.
I created a Gist on GitHub to control the LEDs and a matching and labeled schematic (see below) to demonstrate 20 Charlieplexed LEDs, but I've not actually tested the setup or the code (FYI).
Here's the code:
I threw together a schematic for the project and added labels to the LEDs to help you identify them in the source code.
The AVR chip in the schematic is just a placeholder for your board or chip. It's there to give you an idea.
Also, a better way to control up to 56 LEDs AND save SRAM space on your AVR/Arduino is given in my article on MAKE. But, I copied the Gist over to this article real quick because it's kinda cool to work at the bits and ports level on the AVRs:
With the original (and probably easy-to-read) version of the code, I simply used a multidimensional array to store the INPUT/OUTPUT or HIGH/LOW values for the Arduino pins for the control of any particular LED. The version at the top of the page takes roughly (LED_COUNT x PINS x 2) bytes or memory (20 LEDs = 200 bytes). The version directly above uses individual bytes to change the AVR PINx and DDRx. For 20 LEDs, that's (40) bytes. For 56 LEDs controlled using 8 pins, the big array version would take about 896, whereas the smaller one only requires about 112 bytes.