Two 74HC595 shift registers and 16 LEDs

Hi all, thanks for taking the time to read what must be the millionth post on shift registers.

I have a very basic circuit comprising two 74HC595 shift registers and 16 LEDs, driven by a Duemilanove ATmega328.

My goal (for now) is to have each LED light up one after the other, with the previous LEDs remaining on until all 16 are lit, at which point all go off and the cycle repeats.

For example:

0000 0000 0000 0000 1000 0000 0000 0000 1100 0000 0000 0000 1110 0000 0000 0000 1111 0000 0000 0000 ... 1111 1111 1111 1111 [repeat]

The problem I'm having is that the first eight LEDs sort of do what they're supposed to, in that they light up sequentially and previous LEDs stay lit, but they only flash on for a brief moment, and as further LEDs in the first eight light up, the entire line [of eight] flashes as another one lights up.

When it gets to the second eight LEDs (run from the second shift register), they all light up as they're supposed to.

I have made a short video of what is happening: http://www.youtube.com/watch?v=hMah5LvVnEI

The code I am using is as follows:

int latchPin = 8;
int dataPin = 11;
int clockPin = 12;
int dato = 0;
int waitFor = 200;

int first = 0;
int second = 0;

void setup() {
  pinMode (dataPin, OUTPUT);
  pinMode (clockPin, OUTPUT);
  pinMode (latchPin, OUTPUT);
}

void loop() {
  lightLeds (0b00000000, 0b00000000);
  
  lightLeds (0b00000001, 0b00000000);
  lightLeds (0b00000011, 0b00000000);
  lightLeds (0b00000111, 0b00000000);
  lightLeds (0b00001111, 0b00000000);
  
  lightLeds (0b00011111, 0b00000000);
  lightLeds (0b00111111, 0b00000000);
  lightLeds (0b01111111, 0b00000000);
  lightLeds (0b11111111, 0b00000000);
  
  lightLeds (0b11111111, 0b00000001);
  lightLeds (0b11111111, 0b00000011);
  lightLeds (0b11111111, 0b00000111);
  lightLeds (0b11111111, 0b00001111);
  
  lightLeds (0b11111111, 0b00011111);
  lightLeds (0b11111111, 0b00111111);
  lightLeds (0b11111111, 0b01111111);
  lightLeds (0b11111111, 0b11111111);
}

void lightLeds (int second, int first) {
  digitalWrite (latchPin, LOW);
  shiftOut (dataPin, clockPin, LSBFIRST, first);
  shiftOut (dataPin, clockPin, LSBFIRST, second);
  digitalWrite (latchPin, HIGH);
  delay (waitFor);
}

(The code is a little long-winded, but the reason for that is to allow me to understand how the code works.)

If no one recognises this as a common problem, I can try and draw out the exact circuit I've got. However, the circuit is based on this one:

http://www.protostack.com/blog/2010/05/introduction-to-74hc595-shift-register-controlling-16-leds/

Thanks for taking the time to help, I appreciate it.

Chris

Just looking at your breadboard in the video, it doesn't look like you have /OE tied to ground on the first chip?

You truly are a ninja - thank you so much! Fixed the problem straight away :slight_smile:

drops smoke bomb, runs away