Best way to control 162 outputs in under 1ms ???

I'm making a 9*9*9 Bi-color LED cube which has 9 layers. Each layer is only on for ~1 millisecond, then off for ~8ms while the other 8 layers are cycled.

My problem is that I need to control 162 LEDs fast enough to have them on for ~1ms, and still go through all 9 layers in 16ms or under. I also need the time it takes to tell the 21x, daisychained, 74HC595's to be a short as possible.

Where does 162 come from?

@AWOL: My guess is 162 is all the LEDs in each plane (9x9x2).

@TECH GEEK: 1ms = 16,000 clock cycles (@ the normal 16 Mhz). Using hardware SPI you should be able to shift out 21 bytes of data in under 1000 clock cycles (each bit = 2 cycles * 168 bits = 336 cycles, plus overhead of loops etc). So this should be doable.

Have you looked at the ShiftPWM library ( )? From what I've read it seems to be heavily optimized to do just what you want.

Good luck!