by Francois AUGER & Philippe Fretaud:
Many previous Design Ideas [1, 2] have shown how to use the Charlieplexing technique  to drive as many LEDs as possible with a minimum number of I/O lines. This Design Idea shows how you can drive three LEDs and scan three switches with only three I/O lines instead of six. Using the same principle, it will also be possible to manage four switches and two LEDs, or five LEDs and one switch. It works well with Atmel ATmega microcontrollers including the Arduino, and could be of particular interest for any eight-pin devices, or when you’ve simply run out of I/O.
3 pins, 3 LEDs, 3 buttons – [Link]