This tutorial will show how to control multiple LED outputs from a microcontroller using an STP16C596 shift register. The STP16C596 is similar to the popular 74HC595 shift register, but it’s nicer because it can sink a constant current to the LEDs it’s driving.
This is a stub. More explanation will follow, but for now, here are schematics and code for Arduino.
Parts you’ll need:
- STP16C596 shift register
- Arduino microcontroller
- LEDs
- 1-kilohm resistor
The Circuit
The code
/* Shift Register Example for STP16C596 shift register, but should also work for 74HC595/596 This sketch turns on each of the LEDs attached to a STP16C596 shift register, in sequence from output 0 to output 15. Hardware: * STP16C596 shift register attached to pins 2, 3, and 4 of the Arduino, as detailed below. * LEDs attached to each of the outputs of the shift register Created 22 May 2009 by Tom Igoe http://tigoe.net/pcomp/code/category/arduinowiring/534 for more */ //Pin connected to latch pin (LE) of STP16C596 const int latchPin = 4; //Pin connected to clock pin (CLK) of STP16C596 const int clockPin = 3; ////Pin connected to Data in (SDI) of STP16C596 const int dataPin = 2; void setup() { //set pins to output because they are addressed in the main loop pinMode(latchPin, OUTPUT); pinMode(dataPin, OUTPUT); pinMode(clockPin, OUTPUT); Serial.begin(9600); Serial.println("reset"); } void loop() { // intialize a 16-bit integer (unsigned, to use all 16 bits) // that will hold all the states of the outputs: unsigned int outputStates = 0; // loop over the 16 positions of the shift register, // turning on each one in sequence: for (int thisPosition = 0; thisPosition < 16; thisPosition++) { // take the latch pin low while shifting bits out: digitalWrite(latchPin, LOW); // turn on the next highest bit in outputStates: bitWrite(outputStates, thisPosition, HIGH); // since shiftOut() shifts out a byte, separate // outputStates into two bytes, the high byte // and the low byte: byte highByte = outputStates % 256; byte lowByte = outputStates / 256; // shift the two bytes out: shiftOut(dataPin, clockPin, MSBFIRST, lowByte); shiftOut(dataPin, clockPin, MSBFIRST, highByte); // take the latch pin high at the end of // shifting: digitalWrite(latchPin, HIGH); // delay before turning on next LED: delay(250); } }


