Every microcontroller has a limited number of I/O pins. Sometimes when we need more of them we chose bigger MCU. This isn’t the cure for cases like that especially when we don’t need much of processing power – only more pins. It is better to use port expander. Mike Szczys suggests using 74HC595 shift registers that can be controlled directly with microcontroller SPI module.
Using SPI shift register can be controlled with three MCU pins for clocking, sending data and latch. Actually there can be cascaded as many shift registers as you want the only thing you may loos is I/O speed. In following tutorial there are two 595 registers used that gives 16 controllable pins. Great stuff when you need to deal with massive amount of LEDs.