How much more coding needed for a 2 or more shift register?

How much more or complicated is the coding if I want to add more than just 1 shift register? I have code available that is working for 1 shift reg. But say if I want to add a second or even third or fourth. What's the difference in the coding that I already have? I just needed the 8 led to light up in sequence from the first shift reg. To the second and so on.

int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
 
byte leds = 0;
 
void setup() 
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
}
 
void loop() 
{
  leds = 0;
  updateShiftRegister();
  delay(500);
  for (int i = 0; i < 8; i++)
  {
    bitSet(leds, i);
    updateShiftRegister();
    delay(500);
  }
}
 
void updateShiftRegister()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds);
   digitalWrite(latchPin, HIGH);
}

You have to repeat the shiftOut statement for each of the separate bytes containing the shift register patterns, within the digitalWrite/s for the latchPin. The first byte goes through to the last register in the chain.

Paul_B sorry also forgot to mention I have no prior experience in any coding. When you say repeat the shiftout statement, could you show me how to do that?

int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
 
byte leds1 = 0;
byte leds2 = 0;
byte leds3 = 0;
 
void setup()
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(clockPin, OUTPUT);
}
 
void loop()
{
  leds = 0;
  updateShiftRegister();
  delay(50);
  for (int i = 0; i < 8; i++)
  {
    bitSet(leds1, i);
    updateShiftRegister();
    delay(50);
  }
  leds2++;
  if (leds2 == 0) leds3++;
}
 
void updateShiftRegister()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds1);
   shiftOut(dataPin, clockPin, LSBFIRST, leds2);
   shiftOut(dataPin, clockPin, LSBFIRST, leds3);
   digitalWrite(latchPin, HIGH);
}

Wow, thank you I'll give it a shot.

Paul__B Hey I tried the codes, but it's not turning on all the way through than turn off like it should. I guess a better example would be like an Audi style light, one light on at a time and than once reach to the end of the line which is 16 less then cuts off and repeat.

Sorry, but I gave you code to demonstrate how to drive the chain of three or four shift registers with three or four bytes and which was sufficient to indicate how to adapt it for more or less shift registers. I used a quick generator for the three bytes as a demonstration which does different things to the bytes because I only wanted to demonstrate the principle.

I think you might have to study the code for a bit and figure out for yourself exactly what you want to display and how to code that - I'm a bit short on time just now.

I guess a better example would be like an Audi style light,

Never seen anyone with an Audi actually use an indicator.

When you can calculate the sequence on the fly, you don't need much memory.

(Haven't tested it and when I haven't messed up) This code will work for... lets say 32000 leds.

int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
 
#define ledcount 8
 
void setup()
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(clockPin, OUTPUT);
}

void shiftBit(bool val)
{
  digitalWrite(dataPin, val);
  digitalWrite(clockPin, HIGH);
  digitalWrite(clockPin, LOW);    
}

void resetLeds()
{
  digitalWrite(latchPin, LOW);
  for( int i = 0; i < ledcount; i++)
  {
    shiftBit(false);
  }
  digitalWrite(latchPin, HIGH);
}

void loop()
{
  resetLeds();
  delay(500);
  for (int i = 0; i < ledcount; i++)
  {
    digitalWrite(latchPin, LOW);
    shiftBit(true);
    digitalWrite(latchPin, HIGH);
    delay(500);
  }
}

lets say 32000 leds.

Let’s not.

Each led needs three bytes of memory, it depends on how much memory you have on your Arduino.

Grumpy_Mike:
Each led needs three bytes of memory

These are not NeoPixel, Mike. Just ordinary LEDs driven by shift registers, I think.

Ok missed that, but that still only gives 12000 LEDs and not 32000

How do you get to this number?

Well you need one bit to control each LED. The Uno has 2K of read / write memory. You need some of this memory for the Arduino's running, so saying this is 0.5K, multiply 1500 by 8 to get 12000.

While the exact number will depend on the amount of read / right memory your code takes up this is nowhere close to the 32000 LEDs stated earlier.

How did you come up with your number?

Please show me the line where my code allocates tons of memory.

Grumpy_Mike:
How did you come up with your number?

The for-loop uses int. This overflows at 2^15 which is roughly 32000.

Please show me the line where my code allocates tons of memory.

Please show me where that code of yours can do anything but turn all the LEDs on or off?
Apart from the fact that every bit you toggle the latch.

That code is rubbish.

Grumpy_Mike:
Please show me where that code of yours can do anything but turn all the LEDs on or off?
Apart from the fact that every bit you toggle the latch.

Its supposed to turn all LEDs on one by one. Wasn't the TO asking for this?

That code is rubbish.

I'd like to see some better code