4 shift registers

Hi everyone!

I'm trying to control 40 LED lights by using 5 daisy chained M74HC595B1 shift registers on an arduino uno.

the problem I'm having is that the fourth and fifth shifters are not working. all the LED lights
connected to the 4th and 5th shifter are constantly ON and are not going OFF.

I don't know where the problem is and how to fix it. can anyone help me?

I've attached a photo of the set up I'm using but with 5 registers instead of 2. (they're daisy chained the same way the second shift register is connected to the first shift register.)

This is the code I'm using:

int latchPin = 8;
int dataPin = 11;
int clockPin = 12;
int dato = 0;
int framespeed = 300;

int first = 0; // shifter 1
int second = 0; // shifter 2
int third = 0; // shifter 3
int fourth = 0; // shifter 4
int fifth = 0; // shifter 5

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

void loop() {

lightLeds (0b11111111, 0b00000000, 0b00000000, 0b00000000, 0b00000000); // frame 1
lightLeds (0b00000000, 0b11111111, 0b00000000, 0b00000000, 0b00000000); // frame 2
lightLeds (0b00000000, 0b00000000, 0b11111111, 0b00000000, 0b00000000); // frame 3
lightLeds (0b00000000, 0b00000000, 0b00000000, 0b11111111, 0b00000000); // frame 4
lightLeds (0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11111111); // frame 5
}

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

thankyou,

I'm using but with 5 registers instead of 2. (they're daisy chained the same way the second shift register is connected to the first shift register.)

So you have no decoupling capacitors on any shift register then? Should have a 0.1uF ceramic capacitor across power and ground of every shift register.

int first = 0;  // shifter 1
int second = 0; // shifter 2
int third = 0;  // shifter 3
int fourth = 0; // shifter 4
int fifth = 0;  // shifter 5

Is totally unnecessary these values are local variables passed into your lightLeds function. You do not need separate global variables of the same name that you do nothing with.