The 74HC595 Shift Register

Before I go through the code, let's have a quick look at what the chip is doing, so that we can understand what the code has to do.

The chip is of a type called a shift register.
The shift register holds what can be thought of as eight memory locations, each of which can be a 1 or a 0.

To set each of these values on or off, we feed in the data using the 'Data' and 'Clock' pins of the chip.

The clock pin needs to receive eight pulses, at the time of each pulse, if the data pin is high, then a 1 gets pushed into the shift register, otherwise a 0. When all eight pulses have been received, then enabling the 'Latch' pin copies those eight values to the latch register. This is necessary, otherwise the wrong LEDs would flicker as the data was being loaded into the shift register.

The chip also has an OE (output enable) pin, this is used to enable or disable the outputs all at once. You could attach this to a PWM capable Arduino pin and use 'analogWrite' to control the brightness of the LEDs. This pin is active low, so we tie it to GND.
Last updated on 2015-05-04 at 04.27.11 PM Published on 2012-12-03 at 12.10.00 PM