am i outputting to 4 74HC595 the correct way>

Hi,

I hope you got it working. I found your post because I was looking for a sketch to check 2 shift registers daisy chained. I finally got it working with 16 LEDs in a row. This simple sketch works to check 2 shift registers, modify for more.

I lined my LEDs up so that looking at them from left to right they are connected to Qa-Qh (on 74HC595). The LSB is on the right. With this setup I use the LSBFIRST to shift out the bytes using the shiftOut() function.

The way I look at it is the Arduino shiftOut() clocks in 8 bits at a time, no more, no less. The daisy chained shift registers have d-type flip-flops, chained together and each chip extends the chain. Each bit that comes in moves in an orderly fashion to the next flip-flop as the clock is cycled. So a bit coming in must move all the way through 32 flip-flops when you have 4 SIPO shift registers daisy chained.

Now, in my setup, where Qa is on my left, and Qh is on my right, when I added another shift register (to the right of the first), it becomes the least significant byte and when I shift 1111111100000000 into the two registers (now one big one), I need to break it up into the 2 bytes, and shift out the LSB first, then the MSB, because if I did it the other way around, it looks like this once latched: 0000000011111111

So, for 2 shift registers, you need to shift the top 8 bits right, before you transmit, because the shiftOut() can't SEE the rest of the 16 bits (or 32 etc.) in your variable.

The notes at the bottom of the shiftOut() page explain this: shiftOut() - Arduino Reference

So here is a very simple example using 2 shift registers, and 16 LEDs, arranged so looking at them in a row from left to right, each row is wired to Qa through Qh on the 74HC595.

I added a lot of serial monitor output so you can visualize the code. To make an animation of 4 LEDs appear to move from right to left through all the LEDs then disappear, I needed 10 bytes. I could have also used an array, but this is the raw demo.

// Example code for 2 SIPO shift registers with 16 LEDs.
//
// define pins on Arduino

const int latchPin = 5;
const int clockPin = 6;
const int dataPin = 4;

// unsigned variable to deal with bitshift
unsigned int leds;
int wait = 500;

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  Serial.println("RESET");

  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  // Run at start to clear bits
  leds = 0;
  updateShiftRegister();
  delay(wait);
}

void loop()
{
  Serial.println("LOOP");

  leds = 0x000F;
  updateShiftRegister();
  delay(wait);

  leds = 0x00F0;
  updateShiftRegister();
  delay(wait);

  leds = 0x0F00;
  updateShiftRegister();
  delay(wait);

  leds = 0xF000;
  updateShiftRegister();
  delay(wait);

  leds = 0;
  updateShiftRegister();
  delay(wait);

}

void updateShiftRegister()
{
  Serial.print("shift byte with value 0x");
  Serial.print(leds, HEX);
  Serial.print(" : ");
  Serial.println(leds, BIN);
  digitalWrite(latchPin, LOW);  // keep latch low while sending 16 bits stored in variable
  shiftOut(dataPin, clockPin, LSBFIRST, leds);  // send low byte
  shiftOut(dataPin, clockPin, LSBFIRST, (leds >> 8)); //bitshift and send high byte
  digitalWrite(latchPin, HIGH);
}

This guy has a nice example setup and code for 2 registers: https://www.best-microcontroller-projects.com/74hc595.html

For learning about using 1 shift register, I like this site: https://lastminuteengineers.com/74hc595-shift-register-arduino-tutorial/