How do I use variables in functions/procedures

Well.....thanks for all the replies.
I have two led strips and for some reason both of them fail to light the first 4 leds? they are
64, 0, 0, 0, 0
128, 0, 0, 0, 0
0, 1, 0, 0, 0 and
0, 2, 0, 0, 0
at least those 4 do nothing so I assume they are the addresses of the first four LED's
Paul, I tried to make a sketch from what you offered

const byte ledPin[40] = {18, 19, 20, 21, 22, 23, 32, 33, 34, 35, 36, 37, 10, 11, 38, 39, 24, 25, 12, 13, 14, 15, 26, 27, 28, 29, 0, 1, 2, 3, 30, 31, 16, 17, 4, 5, 6, 7, 8, 9};
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
void setup() {
  // put your setup code here, to run once:
    Serial.begin(9600);
pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
for (int x=0;x < 40; x++)
{
  byte pin = ledPin[x];
  byte sr = pin >> 3;
  byte srBit = pin & 7;
  byte shiftBytes[5] = {0, 0, 0, 0, 0};
  bitWrite(shiftBytes[sr], srBit, 1); 
    digitalWrite(clockPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, srBit);
       delay(30);
         Serial.print (srBit);
    Serial.print ("   ");
    Serial.println (x);
  digitalWrite (latchPin,HIGH);
  digitalWrite (latchPin,LOW);
  delay(2000);
}
}

but couldn't work out what to call in the shiftout line, at least I think that is my problem.

J-M-L jackson, I took your sketch and altered some of it especially the loop function, I turned it into a 'for' loop

const byte dataPin = 11;
const byte clockPin = 12;
const byte latchPin = 8;
byte ledPatterns[40][5] = 
{
  {64,0,0,0,0},{128,0,0,0,0},{0,1,0,0,0},{0,2,0,0,0},
  {0,0,4,0,0},{0,0,8,0,0},{0,0,16,0,0},{0,0,32,0,0},{0,0,64,0,0},
  {0,0,128,0,0},{0,0,0,0,1},{0,0,0,0,2},{0,0,0,0,4},{0,0,0,0,8},
  {0,0,0,0,16},{0,0,0,0,32},{0,4,0,0,0},{0,8,0,0,0},{0,0,0,0,64},
  {0,0,0,0,128},{0,0,0,1,0},{0,0,0,2,0},{0,16,0,0,0},{0,32,0,0,0},
  {0,64,0,0,0},{0,128,0,0,0},{0,0,0,4,0},{0,0,0,8,0},{0,0,0,16,0},
  {0,0,0,32,0},{1,0,0,0,0},{2,0,0,0,0},{4,0,0,0,0},{8,0,0,0,0},
  {0,0,0,64,0},{0,0,0,128,0},{0,0,1,0,0},{0,0,2,0,0},{16,0,0,0,0},
  {32,0,0,0,0}
};
// shadow array holds current state of all 5 shift registers
byte shadow[5] = {0,0,0,0,0};
void setLED(int pinNumber, bool state) 
{
  for(int i = 0; i < 5; i++) 
  {
    if(state) shadow[i] |= ledPatterns[pinNumber][i];
    else shadow[i] &= ~ledPatterns[pinNumber][i];
  }
  digitalWrite(latchPin, LOW);
  for(int i = 0; i < 5; i++) 
  {
    shiftOut(dataPin, clockPin, MSBFIRST, shadow[i]);
  }
  digitalWrite(latchPin, HIGH);
}
void setup() {
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
}
void loop() {
  for(int i = 0; i < 40; i++) 
  {
    setLED(i, HIGH);
    delay(100);
    setLED(i, LOW);
    delay(10);
  }
}

It now works quite well.

KenB4, I altered some of the sketch to make it work but again I think I am calling the wrong thing in the shiftout line

enum Chip : byte {_1ST = 1, _2ND, _3RD, _4TH, LAST};

struct Foo {  // no idea what to call this
  Chip chip;
  byte value;
};
const byte dataPin = 11;
const byte clockPin = 12;
const byte latchPin = 8;
Foo leds[] = {
  {_3RD, 252},
  {_4TH, 63},
  {_2ND, 12},
  {LAST, 0b11000000},  // or use the bits directly
};

void doWhatever() 
{
  for (Foo &f : leds) 
  {  // loop through them all
    Serial.print(f.chip);
    Serial.print('\t');
    Serial.println(f.value);

    bool firstBit = false;
    for (int m = 0; m < 8; m++) 
    {
      byte mask = 1 << m;
      if (mask > f.value) 
      {
        break;
      }
      byte bit = f.value & mask;
      if (bit || firstBit) 
        {
        firstBit = true;
         digitalWrite(latchPin, LOW);
        for (int c = _1ST; c <= LAST; c++) 
         {  // easy to reverse chip order
          Serial.print(f.chip == c ? bit : 0);  // replace with shiftOut()
          shiftOut(dataPin, clockPin, MSBFIRST, bit);
           Serial.print(c == LAST ? '\n' : '\t');
           delay(250);
         }
          digitalWrite(latchPin, HIGH);
        }
      }
    }
  }


void setup() {
  Serial.begin(115200);
}

void loop() {
  doWhatever();
  delay(2500);
}

J-M-L jackson, this one almost works, it does a full sweep but then adds two flashes of led 31 which is 1,0,0,0,0 which I can't see the reason for?

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

struct LED {
  byte reg;   // shift register index 0..4
  byte bit;   // bit position 0..7
};

// define LEDs by which register and which bit
const LED leds[] = {
 // {0,0},{0,0},{0,0},{0,0},{0,0}, // placeholders 0–4
  {2,2}, {2,3}, {2,4}, {2,5}, {2,6},
  {2,7}, {4,0}, {4,1}, {4,2}, {4,3},
  {4,4}, {4,5}, {1,2}, {1,3}, {4,6},
  {4,7}, {3,0}, {3,1}, {1,4}, {1,5},
  {1,6}, {1,7}, {3,2}, {3,3}, {3,4},
  {3,5}, {0,0}, {0,1}, {0,2}, {0,3},
  {3,6}, {3,7}, {2,0}, {2,1}, {0,4},
  {0,5}
};

byte shadow[] = {0,0,0,0,0};

void setLED(int pinNumber, bool state) {
  LED l = leds[pinNumber];
  if(state) shadow[l.reg] |= (1 << l.bit);
  else shadow[l.reg] &= ~(1 << l.bit);

  digitalWrite(latchPin, LOW);
  for(int i = 0; i < 5; i++) shiftOut(dataPin, clockPin, MSBFIRST, shadow[i]);
  digitalWrite(latchPin, HIGH);
}

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

void loop() {
  for(int i = 0; i < 41; i++)
  {
  setLED(i, HIGH);
  delay(100);
  setLED(i, LOW);
  delay(30);
  }
}


gcjr, thanks, that looks even longer :slightly_smiling_face: