shiftout

So this example code:

const int latchPin = 8;
const int clockPin = 12;
const int dataPin = 11;

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);
}
void loop() {
  // iterate over the 16 outputs of the two shift registers
  for (int thisLed = 0; thisLed < 16; thisLed++) {
    // write data to the shift registers:
    registerWrite(thisLed, LOW);
    // if this is not the first LED, turn off the previous LED:
    if (thisLed >= 0) {
      registerWrite(thisLed - 1, HIGH);
    } 
    // if this is  the first LED, turn off the highest LED:
    else {
      registerWrite(15, HIGH);
    } 
    // pause between LEDs:
    delay(130);
  }  
    for (int thisLed = 16; thisLed > 0; thisLed--) {
      
    registerWrite(thisLed, LOW);
    
    if (thisLed >= 0) {
      registerWrite(thisLed - 1, HIGH);
    } 
    else {
      registerWrite(15, HIGH);
    } 
    delay(130);
  }
}

// This method sends bits to the shift registers:

void registerWrite(int whichPin, int whichState) {
  // the bits you want to send. Use an unsigned int,
  // so you can use all 16 bits:
  unsigned int bitsToSend = 0;    

  // turn off the output so the pins don't light up
  // while you're shifting bits:
  digitalWrite(latchPin, LOW);

  // turn on the next highest bit in bitsToSend:
  bitWrite(bitsToSend, whichPin, whichState);

  // break the bits into two bytes, one for 
  // the first register and one for the second:
  byte registerOne = highByte(bitsToSend);
  byte registerTwo = lowByte(bitsToSend);

  // shift the bytes out:
  shiftOut(dataPin, clockPin, MSBFIRST, registerTwo);
  shiftOut(dataPin, clockPin, MSBFIRST, registerOne);
  

  // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, HIGH);
}

let me shift out the code to 2 registers. I tried using

byte registerThree = highByte(bitsToSend);

under

byte registerOne = highByte(bitsToSend);
byte registerTwo = lowByte(bitsToSend);

so it can shift out a third bit but it doesn’t work. I am trying to shift out the code the a third register. which part should i modify??
thanks

add
shiftOut(dataPin, clockPin, MSBFIRST, registerThree);
before the shiftout for registerTwo

Do you want to change the middle variable to middleByte(bitsToSend) so the 2nd ^& 3rd displays aren’t the same all the time?
Probably need to change your approach here also
for (int thisLed = 0; thisLed < 16; thisLed++) {
so that you have 24 bits to play with.
thisLed needs to be type long vs int.

CrossRoads: Do you want to change the middle variable to middleByte(bitsToSend) so the 2nd ^& 3rd displays aren't the same all the time?

Yes. I tried

byte registerOne = highByte(bitsToSend); byte registerTwo = lowByte(bitsToSend); byte registeThree = highByte(bitsToSend);

but the 2nd and 3rd are still running the same..

You misunderstand.

Your function does this

  // break the bits into two bytes, one for 
  // the first register and one for the second:
  byte registerOne = highByte(bitsToSend);
  byte registerTwo = lowByte(bitsToSend);

  // shift the bytes out:
  shiftOut(dataPin, clockPin, MSBFIRST, registerTwo);
  shiftOut(dataPin, clockPin, MSBFIRST, registerOne);

There is nothing there to make the 3rd shift register/LED do anything. That's why I said you needed to expand things to be 24 bits.

CrossRoads: You misunderstand.

Your function does this

  // break the bits into two bytes, one for 
  // the first register and one for the second:
  byte registerOne = highByte(bitsToSend);
  byte registerTwo = lowByte(bitsToSend);

what should i put in for this right here, since i can't do byte registerThree highByte or lowByte (bitsToSend);

If you want the 3 shiftouts to have 3 different values, then you have to reorganize.

Look here -everything is set for 16 bits int type variables: Go thru and understand what is doing wiht 16 bits, then change things to long and unsigned long so you have a 32bit variablee to work with, and use 24 bits of it.

// This method sends bits to the shift registers:

void registerWrite(int whichPin, int whichState) {
  // the bits you want to send. Use an unsigned int,
  // so you can use all 16 bits:
  unsigned int bitsToSend = 0;