Code for dual shift register 74HC595

Hello, I am a new registered member ( from Belgium) . In the past ,I was a reader of the forum but no active user.
Now I would to ask your help because I have some problems.

I want to switch 16 relays in a pattern.
First, I would like to switch relay 1 and display this on an LCD.
Then with a push on a button I want to switch relay 2 and display this.
Then relay 3, … up to 16. Below I have posted a code but this does not work properly.
Can someone modify the code ( for example shifting relay 1 to 7)?
How can i send multiple relays together. What is the rule or code therefor? For example, what is the code when i want to switch relay 2 and 8 together?

I use a Arduino UNO with a dual shift register (2x74HC595).
The outputs of the 2 shift register are connected with a ULN2803 (2X) . The outputs of the ULN2803 are connected with the relays.

thanks in advance;

 //LCD- scherm// 
 //include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);          => updated ( was LiquidCrystal lcd(12, 11, 5, 4, 3, 13); => fault)

int switchPin = A0;              // drukknop aangesloten op in A0
int latchpin = 2;               //Pin aangesloten op ST_CP van 74HC595
int clockpin = 3;                //Pin aangesloten op SH_CP van 74HC595
int datapin = 4;                  //Pin aangesloten op DS van 74HC595


int val;                        // variable for reading the pin status
int val2;  
int buttonState;  

byte data = 0; 
int Mode = 0;             

void setup() {
  

  // initialize serial communication with computer:                  
  Serial.begin(9600);           // Set up serial communication at 9600bps
 buttonState = digitalRead(switchPin);   // read the initial state
 
 pinMode(latchpin, OUTPUT);
 pinMode(clockpin, OUTPUT);
 pinMode(datapin, OUTPUT);
 pinMode(switchPin, INPUT);    // Set the switch pin as input


lcd.begin(16, 2);
lcd.print("Test");    // LCD schrijven

}

void loop(){{
 
  val = digitalRead(switchPin);      // read input value and store it in val
  delay(5);                         // 10 milliseconds is a good amount of time
  val2 = digitalRead(switchPin);     // read the input again to check for bounces
  if (val == val2) {                 // make sure we got 2 consistant readings!
    if (val != buttonState) {          // the button state has changed!
      if (val == LOW) {                // check if the button is pressed
        if (Mode == 0) {Mode = 1; } 
              else {
            if (Mode == 1) {Mode = 2; } 
              else {
              if (Mode == 2) {Mode = 3;}
              else {
                if (Mode == 3) { Mode = 4; }
               else {
                    if (Mode == 4) {Mode = 5; }
              else {
		   if (Mode == 5) { Mode = 6;}
              else {
                    if (Mode == 6) { Mode = 7;}
              else {
                if (Mode == 7) { Mode = 0;}}}}}}}}}}}
 buttonState = val;                 // save the new state in our variable
  }
  
  
if (Mode == 1) { 
  
 digitalWrite(latchpin, LOW);
 shiftOut(datapin, clockpin, MSBFIRST, 0);
 shiftOut(datapin, clockpin, MSBFIRST, 0); 
 digitalWrite(latchpin, HIGH);

 
lcd.setCursor(0, 0);
lcd.print("mode1  ");}


if (Mode == 2) { 
  
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 1);
shiftOut(datapin, clockpin, MSBFIRST, 0);
digitalWrite(latchpin, HIGH);

lcd.setCursor(0, 0);
lcd.print("mode2     ");}

if (Mode == 3) { 
  
 digitalWrite(latchpin, LOW);
 shiftOut(datapin, clockpin, MSBFIRST, 2);
 shiftOut(datapin, clockpin, MSBFIRST, 0);
 digitalWrite(latchpin, HIGH);
  
lcd.setCursor(0, 0);
lcd.print("mode3     "); }
 
if (Mode == 4) { 
 
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 4);
shiftOut(datapin, clockpin, MSBFIRST, 0);
digitalWrite(latchpin, HIGH); 
 
  
lcd.setCursor(0, 0);
lcd.print("mode 4 ");} 

if (Mode == 5) { 
 
 digitalWrite(latchpin, LOW);
 shiftOut(datapin, clockpin, MSBFIRST, 8);
 shiftOut(datapin, clockpin, MSBFIRST, 0);
 digitalWrite(latchpin, HIGH);
  
lcd.setCursor(0, 0);
lcd.print("Mode 5                                   ");
 
if (Mode == 6) { 
  
  digitalWrite(latchpin, LOW);
  shiftOut(datapin, clockpin, MSBFIRST, 16);
  shiftOut(datapin, clockpin, MSBFIRST, 0);
  digitalWrite(latchpin, HIGH);
  
  lcd.setCursor(0, 0);
  lcd.print("Mode 6         ");
}}}
LiquidCrystal lcd(12, 11, 5, 4, 3, 13);

int switchPin = A0;              // drukknop aangesloten op in A0
int latchpin = 2;               //Pin aangesloten op ST_CP van 74HC595
int clockpin = 3;                //Pin aangesloten op SH_CP van 74HC595
int datapin = 4;                  //Pin aangesloten op DS van 74HC595

What is really connected to pins 3 and 4? Is it the shift register or the LCD?

        if (Mode == 0) {Mode = 1; } 
              else {
            if (Mode == 1) {Mode = 2; } 
              else {
              if (Mode == 2) {Mode = 3;}
              else {
                if (Mode == 3) { Mode = 4; }
               else {
                    if (Mode == 4) {Mode = 5; }
              else {
           if (Mode == 5) { Mode = 6;}
              else {
                    if (Mode == 6) { Mode = 7;}
              else {
                if (Mode == 7) { Mode = 0;}}}}}}}}}}}

That's a shitload of code to do:

   Mode++;
   if(Mode == 7)
      Mode = 0;

-What is really connected to pins 3 and 4? Is it the shift register or the LCD: : LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

=> the shift register is connected on pin 2,3,4

So where did this line LiquidCrystal lcd(12, 11, 5, 4, 3, 13); come from?

I have updated the first post. It was a fault in my code.

AWOL: So where did this line LiquidCrystal lcd(12, 11, 5, 4, 3, 13); come from?

What about fixing the horrid code to change Mode?

What about using Tools + Auto Format to make the rest of the code presentable?

What about describing what the code actually does? What about describing how that differs from what you want?

Hello and welcome :)

Look this small and useful library: http://bildr.org/2011/08/74hc595-breakout-arduino/