I was in the lab last week and we got onto the topic of seven segment displays. Someone then proposed the challenge of driving it using only 4 I/Os without a driver. A very interesting challenge indeed.
After much deliberation they finally shared the secret of Charlieplexing. This is a basic way to control large arrays of LEDs using just a few pins. In fact the equation works out as follows:
L = n^2 - n
Where L is the number of LEDs controlled and n is the number of pins that are used.
Personally, I love this. I love LEDs and I love controlling them. Some possible project include using this method for larger LED cubes, 7-segment driving, and other fantastical inventions.
Anyway, The circuit is actually pretty simple and available at the end of the video above. As for the code, it is just a matter of reassigning the pins to output or input on the fly and then changing the state of the other outputs. This goes into how it works. With a 3 pin setup, one pin must be changed to an input or high impedance state. The other pins act as your outputs and depending on which one is set HIGH or LOW you can have individual control.
There are drawbacks, Can't control multiple LEDs at a time (i.e. light 1 and 5). the way around this is to actually "flicker" the LEDs involved at 60hz which is unnoticeable to the naked eye.
For more info, Visit the Wiki.