- Configure SPI
- Hook up your shift registers
- common
SS
- common
CLK
QH*
of the first shift register to SER
of the next
In order to transfer the bytes
- Pull
SS
low
ShiftOut
first byte
ShiftOut
next byte
- Pull
SS
high again to finish the SPI transfer
UPDATE
This is untested, just out of memory!
#include<SPI.h>
// note that the pins for CLK and MOSI are defined here
unsigned int ledPattern = 0b1111000011110000;
// store the state for 16 LEDs here
void setup(void)
{
pinMode(SS, OUTPUT);
digitalWrite(SS, HIGH);
SPI.setDataMode(3);
SPI.setClockDivider(4);
SPI.setBitOrder(MSBFIRST);
// let's transfer 2 bytes
digitalWrite(SS, LOW);
SPI.transfer(ledPattern & 0xff00;) // high byte
SPI.transfer(ledPattern & 0x00ff;) // low byte
digitalWrite(SS, HIGH);
}
UPDATE II
You are by no means limited to 2 shift registers! In 2013, we did a 8x11 LED display for an upcycling art project. Eleven 74HC595 were chained to display some patterns. Each 'pixel' consisted of 3 12V SMD LEDs on a stripe. Consequently, each shift register was connected to an ULN2803
.
I just uploaded a video from the construction phase, showing a test pattern.