Driving more LEDs using lesser number of GPIOs

Question: How do I drive more LEDs using lesser number of GPIOs ?

 

Answer:

You can drive (n)*(n-1) number of LEDs by using n number of pins. In order to switch an LED ON or OFF you need to change the drive mode of the pins associated with the LEDs.

Here is an example for driving 6 LEDs using 3 pins. You can refer to the figure below for setting the drive modes and the schematic of the LEDs.