How do you control 3 LEDS with only 3 wires?
Impossible, right? Wrong.
Charlieplexing is a mechanism to do just that. It was developed by Charles Allen at Maxim.
Because LEDS are diodes they only work in one direction – and they only work above a certain voltage. These characteristics can be used to help control them in a multiplexing fashion. Imagine for example you had TWO wires – surely you can only drive one LED with that. Well no. Imagine you put 2 LEDS and their associated resistors across the two wires – but in the opposite direction. Take wire A high and B low… and one of the LEDS will light up – takes wire A low and B high and the OTHER LED will light up. 2 wires, 2 LEDS.
So how many LEDS can you multiplex onto 3 pins… 3, 4, 5… no – SIX
And here’s a library suitable for Arduino-like chips I spotted out in the wild!