Need help creating value for shift register

Hi all,

I am experimenting with 74HC595. What I am trying to accomplish in this step is to replace 8 output pins with a shift register connected t 3 pins as usual.

I made a scetch just to see the project work with 8 input switches affecting 8 input pins and 8 outputs, each connected to a dummy diode to see it working. The code was as follows:

//Declaring input pins

byte inPin0 = A0;   // pushbutton connected to analog pin A0
byte inPin1 = A1;   // pushbutton connected to analog pin A1
byte inPin2 = A2;   // pushbutton connected to analog pin A2
byte inPin3 = A3;   // pushbutton connected to analog pin A3
byte inPin4 = A4;   // pushbutton connected to analog pin A4
byte inPin5 = A5;   // pushbutton connected to analog pin A5
byte inPin6 = 2;    // pushbutton connected to digital pin 2
byte inPin7 = 3;    // pushbutton connected to digital pin 3

//Declaring output pins

byte outPin0 = 6;   // LED connected to digital pin 6
byte outPin1 = 7;   // LED connected to digital pin 7
byte outPin2 = 8;   // LED connected to digital pin 8
byte outPin3 = 9;   // LED connected to digital pin 9
byte outPin4 = 10;  // LED connected to digital pin 10
byte outPin5 = 11;  // LED connected to digital pin 11
byte outPin6 = 12;  // LED connected to digital pin 12
byte outPin7 = 13;  // internal LED connected to digital pin 6

//Declaring variables for storing the value of each output pin

byte val0 = 0;      // variable to store the read value of outPin0
byte val1 = 0;      // variable to store the read value of outPin1
byte val2 = 0;      // variable to store the read value of outPin2
byte val3 = 0;      // variable to store the read value of outPin3
byte val4 = 0;      // variable to store the read value of outPin4
byte val5 = 0;      // variable to store the read value of outPin5
byte val6 = 0;      // variable to store the read value of outPin6
byte val7 = 0;      // variable to store the read value of outPin7

void setup() {
  // Declare input variables:
  pinMode(inPin0, INPUT);        // sets the analog pin A0 as input
  pinMode(inPin1, INPUT);        // sets the analog pin A1 as input
  pinMode(inPin2, INPUT);        // sets the analog pin A2 as input
  pinMode(inPin3, INPUT);        // sets the analog pin A3 as input
  pinMode(inPin4, INPUT);        // sets the analog pin A4 as input
  pinMode(inPin5, INPUT);        // sets the analog pin A5 as input
  pinMode(inPin6, INPUT);        // sets the digital pin 3 as input
  pinMode(inPin7, INPUT);        // sets the digital pin 4 as input

  // Declare output variables:
  pinMode(outPin0, OUTPUT);      // sets the digital pin 6 as output
  pinMode(outPin1, OUTPUT);      // sets the digital pin 7 as output
  pinMode(outPin2, OUTPUT);      // sets the digital pin 8 as output
  pinMode(outPin3, OUTPUT);      // sets the digital pin 9 as output
  pinMode(outPin4, OUTPUT);      // sets the digital pin 10 as output
  pinMode(outPin5, OUTPUT);      // sets the digital pin 11 as output
  pinMode(outPin6, OUTPUT);      // sets the digital pin 12 as output
  pinMode(outPin7, OUTPUT);      // sets the digital pin 13 as output
  
}

void loop() {
  // Read input pin value and set that value on output pin:
  val0 = digitalRead(inPin0);     // read the input pin 0
  val1 = digitalRead(inPin1);     // read the input pin 1
  val2 = digitalRead(inPin2);     // read the input pin 2
  val3 = digitalRead(inPin3);     // read the input pin 3
  val4 = digitalRead(inPin4);     // read the input pin 4
  val5 = digitalRead(inPin5);     // read the input pin 5
  val6 = digitalRead(inPin6);     // read the input pin 6
  val7 = digitalRead(inPin7);     // read the input pin 7

  //Set input pin value to output pin
  digitalWrite(outPin0, val0);    // sets connecting the LED to the button's value
  digitalWrite(outPin1, val1);    // sets connecting the LED to the button's value
  digitalWrite(outPin2, val2);    // sets connecting the LED to the button's value
  digitalWrite(outPin3, val3);    // sets connecting the LED to the button's value
  digitalWrite(outPin4, val4);    // sets connecting the LED to the button's value
  digitalWrite(outPin5, val5);    // sets connecting the LED to the button's value
  digitalWrite(outPin6, val6);    // sets connecting the LED to the button's value
  digitalWrite(outPin7, val7);    // sets connecting the LED to the button's value
  

}

It worked as intended, pushing any button or several at once lighted up corresponding diodes.

So now I am trying to learn how to replace output pins with a shift register. What I am intending to do is to make a value for the shift register according to which buttons are pressed. If button 0 is pressed the values shall be B00000001, if button 1 B00000010, if button 2 and 1 B00000110. I think that is the syntax.

So my question is, how do I make a value from val0-7 so send in to the shift register?

Code I'm working with:

//Declaring input pins

byte inPin0 = A0;   // pushbutton connected to analog pin A0
byte inPin1 = A1;   // pushbutton connected to analog pin A1
byte inPin2 = A2;   // pushbutton connected to analog pin A2
byte inPin3 = A3;   // pushbutton connected to analog pin A3
byte inPin4 = A4;   // pushbutton connected to analog pin A4
byte inPin5 = A5;   // pushbutton connected to analog pin A5
byte inPin6 = 2;    // pushbutton connected to digital pin 2
byte inPin7 = 3;    // pushbutton connected to digital pin 3

//Declaring output pins

int latchPin = 6;   //Pin connected to ST_CP(pin 12) of 74HC595
int clockPin = 7;   //Pin connected to SH_CP(pin 11) of 74HC595
int dataPin = 8;    //Pin connected to DS(pin 14) of 74HC595

//Declaring variables for storing the value of each output pin

byte val0 = 0;      // variable to store the read value of outPin0
byte val1 = 0;      // variable to store the read value of outPin1
byte val2 = 0;      // variable to store the read value of outPin2
byte val3 = 0;      // variable to store the read value of outPin3
byte val4 = 0;      // variable to store the read value of outPin4
byte val5 = 0;      // variable to store the read value of outPin5
byte val6 = 0;      // variable to store the read value of outPin6
byte val7 = 0;      // variable to store the read value of outPin7

void setup() {
  // Declare input variables:
  pinMode(inPin0, INPUT);        // sets the analog pin A0 as input
  pinMode(inPin1, INPUT);        // sets the analog pin A1 as input
  pinMode(inPin2, INPUT);        // sets the analog pin A2 as input
  pinMode(inPin3, INPUT);        // sets the analog pin A3 as input
  pinMode(inPin4, INPUT);        // sets the analog pin A4 as input
  pinMode(inPin5, INPUT);        // sets the analog pin A5 as input
  pinMode(inPin6, INPUT);        // sets the digital pin 3 as input
  pinMode(inPin7, INPUT);        // sets the digital pin 4 as input

  // Declare output pins to 74HC595:
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  
}

void loop() {
  // Read input pin value and set that value on output pin:
  val0 = digitalRead(inPin0);     // read the input pin 0
  val1 = digitalRead(inPin1);     // read the input pin 1
  val2 = digitalRead(inPin2);     // read the input pin 2
  val3 = digitalRead(inPin3);     // read the input pin 3
  val4 = digitalRead(inPin4);     // read the input pin 4
  val5 = digitalRead(inPin5);     // read the input pin 5
  val6 = digitalRead(inPin6);     // read the input pin 6
  val7 = digitalRead(inPin7);     // read the input pin 7

  //value to send shall be in the form of B00000001 with the 1's corresponding to the pressed buttons

  //Set input to 74HC595
  {
    digitalWrite(latchPin, LOW); //Pull latch LOW to send data
    shiftOut(dataPin, clockPin, MSBFIRST, valueToSend); //Send the data
    digitalWrite(latchPin, HIGH); // Pull latch HIGH to stop sending data
    delay(200);
  }
  

}

Best regards
Staffan

stajo:
So my question is, how do I make a value from val0-7 so send in to the shift register?

Simplest would be to use bitWrite from the switches to the byte assigned as the shift register data.

The following link is a nice tutorial using an arduino and 74c595

Thank you. What I think I dont understand, as a non programmer, is how to collect the input pin status in a form presentable to the ShiftRegister, that gets updated by a new input pin status. I cant find any example that reads pin status and transforms them to a byte, ie sequence of bits. Sorry for bad programming vocabulary. I'm trying learning by doing.

//Declaring input pins

byte inPin0 = A0;   // pushbutton connected to analog pin A0
byte inPin1 = A1;   // pushbutton connected to analog pin A1
byte inPin2 = A2;   // pushbutton connected to analog pin A2
byte inPin3 = A3;   // pushbutton connected to analog pin A3
byte inPin4 = A4;   // pushbutton connected to analog pin A4
byte inPin5 = A5;   // pushbutton connected to analog pin A5
byte inPin6 = 2;    // pushbutton connected to digital pin 2
byte inPin7 = 3;    // pushbutton connected to digital pin 3

//Declaring output pins

int latchPin = 6;   //Pin connected to ST_CP(pin 12) of 74HC595
int clockPin = 7;   //Pin connected to SH_CP(pin 11) of 74HC595
int dataPin = 8;    //Pin connected to DS(pin 14) of 74HC595

//Declaring variables for storing the value of each output pin

int whichPin;
int whichState;
byte bitsToSend;
byte currentBits;


void setup() {
  // Declare input variables:
  pinMode(inPin0, INPUT);        // sets the analog pin A0 as input
  pinMode(inPin1, INPUT);        // sets the analog pin A1 as input
  pinMode(inPin2, INPUT);        // sets the analog pin A2 as input
  pinMode(inPin3, INPUT);        // sets the analog pin A3 as input
  pinMode(inPin4, INPUT);        // sets the analog pin A4 as input
  pinMode(inPin5, INPUT);        // sets the analog pin A5 as input
  pinMode(inPin6, INPUT);        // sets the digital pin 3 as input
  pinMode(inPin7, INPUT);        // sets the digital pin 4 as input

  // Declare output pins to 74HC595:
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  
}

void loop() {
  
  //Collect the input pin status (currentBits, bitsToSend?) here and present them for writing to the ShiftRegister
}
  // This method sends bits to the shift register:

void registerWrite(int whichPin, int whichState) {
  // the bits you want to send
  byte bitsToSend = currentBits;

  // Pull latch LOW to send data
  digitalWrite(latchPin, LOW);

  // Modify the correct bit:
  bitWrite(bitsToSend, whichPin, whichState);

  // shift the bits out:
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);

  currentBits = bitsToSend;
  
 // turn on the output enable so the LEDs can light up. OE is used to have a consistent state at startup:
 // digitalWrite(oePin, LOW);

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

  delay(200);
  
  }
if (digitalRead(inPin0) == HIGH)
  {
     bitSet(bitsToSend, 0);
  }

or

bitSet(bitsToSend, (digitalRead(inPin0));

Adjust the HIGH/LOW logic to suit your circuit

Thank you. With below code I can light up output pins 1-7 on the Shift Register, not pin 0. And they stay lighted, they dont go away when released. Any hints?

//Declaring input pins

byte inPin0 = A0;   // pushbutton connected to analog pin A0
byte inPin1 = A1;   // pushbutton connected to analog pin A1
byte inPin2 = A2;   // pushbutton connected to analog pin A2
byte inPin3 = A3;   // pushbutton connected to analog pin A3
byte inPin4 = A4;   // pushbutton connected to analog pin A4
byte inPin5 = A5;   // pushbutton connected to analog pin A5
byte inPin6 = 2;    // pushbutton connected to digital pin 2
byte inPin7 = 3;    // pushbutton connected to digital pin 3

//Declaring output pins

int latchPin = 6;   //Pin connected to ST_CP(pin 12) of 74HC595
int clockPin = 7;   //Pin connected to SH_CP(pin 11) of 74HC595
int dataPin = 8;    //Pin connected to DS(pin 14) of 74HC595

//Declaring variables for storing the value of each output pin

int whichPin;
int whichState;
byte bitsToSend;

void setup() {
  // Declare input variables:
  pinMode(inPin0, INPUT);        // sets the analog pin A0 as input
  pinMode(inPin1, INPUT);        // sets the analog pin A1 as input
  pinMode(inPin2, INPUT);        // sets the analog pin A2 as input
  pinMode(inPin3, INPUT);        // sets the analog pin A3 as input
  pinMode(inPin4, INPUT);        // sets the analog pin A4 as input
  pinMode(inPin5, INPUT);        // sets the analog pin A5 as input
  pinMode(inPin6, INPUT);        // sets the digital pin 3 as input
  pinMode(inPin7, INPUT);        // sets the digital pin 4 as input

  // Declare output pins to 74HC595:
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  
}

void loop() {
  
  // This method sends bits to the shift register:


if (digitalRead(inPin0) == HIGH)
  {
     bitSet(bitsToSend, 0);
  }
if (digitalRead(inPin1) == HIGH)
  {
     bitSet(bitsToSend, 1);
  }
if (digitalRead(inPin2) == HIGH)
  {
     bitSet(bitsToSend, 2);
  }
if (digitalRead(inPin3) == HIGH)
  {
     bitSet(bitsToSend, 3);
  }
if (digitalRead(inPin4) == HIGH)
  {
     bitSet(bitsToSend, 4);
  }
if (digitalRead(inPin5) == HIGH)
  {
     bitSet(bitsToSend, 5);
  }
if (digitalRead(inPin6) == HIGH)
  {
     bitSet(bitsToSend, 6);
  }
if (digitalRead(inPin7) == HIGH)
  {
     bitSet(bitsToSend, 7);
  }

  // Pull latch LOW to send data
  digitalWrite(latchPin, LOW);

  // Modify the correct bit:
  bitWrite(bitsToSend, whichPin, whichState);

  // shift the bits out:
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);

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

  delay(200);
  
  }

not pin 0

Does inPin0 ever go HIGH ? Put in some Serial.print()s to see whether it does. What keeps it LOW when the button is not pressed ?

they stay lighted, they dont go away when released. Any hints?

Set bitsToSend to zero (all bits off) before reading the inputs

I suppose I should point out that there is a neater way to read all 8 inputs and set the bits using an array of input pin numbers and a for loop

UKHeliBob:

Please do if you like. Meanwhile I will try investigate HW and SW malfunctions and a way to zero the bits before reading the inputs.

You should probably also trace through and see how the bits in bitstoSend ever gets set to 0. Ironically the solution will make your code much shorter.

stajo:
Please do if you like.

We can't. We don't have you hardware.

stajo:
Meanwhile I will try investigate HW and SW malfunctions and a way to zero the bits before reading the inputs.

In the meantime, we will wait for your results. Thanks.

adwsystems:
You should probably also trace through and see how the bits in bitstoSend ever gets set to 0. Ironically the solution will make your code much shorter.

Thank you for your interest.

I'm afraid I dont have your sharp debug eyes on the 0 pin.

But I have come so far that i have managed to see in the Serial Printer that inPin0 gets recorded by pressing, I also switched some cables to see and it is reacting. The 0 pin on the ShiftRegister doesnt seem to ever go high though, I guess adwsystems has spotted why.

I have also gotten the outputs to turn off when released, thank you for that UKHeliBob.

And here is the code for that

//Declaring input pins

byte inPin0 = A0;   // pushbutton connected to analog pin A0
byte inPin1 = A1;   // pushbutton connected to analog pin A1
byte inPin2 = A2;   // pushbutton connected to analog pin A2
byte inPin3 = A3;   // pushbutton connected to analog pin A3
byte inPin4 = A4;   // pushbutton connected to analog pin A4
byte inPin5 = A5;   // pushbutton connected to analog pin A5
byte inPin6 = 2;    // pushbutton connected to digital pin 2
byte inPin7 = 3;    // pushbutton connected to digital pin 3

//Declaring output pins

int latchPin = 6;   //Pin connected to ST_CP(pin 12) of 74HC595
int clockPin = 7;   //Pin connected to SH_CP(pin 11) of 74HC595
int dataPin = 8;    //Pin connected to DS(pin 14) of 74HC595

//Declaring variables for storing the value of each output pin

int whichPin;
int whichState;
byte bitsToSend;


void setup() {
  
  // Declare input variables:
  pinMode(inPin0, INPUT);        // sets the analog pin A0 as input
  pinMode(inPin1, INPUT);        // sets the analog pin A1 as input
  pinMode(inPin2, INPUT);        // sets the analog pin A2 as input
  pinMode(inPin3, INPUT);        // sets the analog pin A3 as input
  pinMode(inPin4, INPUT);        // sets the analog pin A4 as input
  pinMode(inPin5, INPUT);        // sets the analog pin A5 as input
  pinMode(inPin6, INPUT);        // sets the digital pin 3 as input
  pinMode(inPin7, INPUT);        // sets the digital pin 4 as input

  // Declare output pins to 74HC595:
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  Serial.begin(9600);
}

void loop() {

  bitsToSend = 0;
  
  // Read the inputs and send HIGH bit values to the corresponding pin on the shift register

if (digitalRead(inPin0) == HIGH)
  {
     bitSet(bitsToSend, 0);
  }
if (digitalRead(inPin1) == HIGH)
  {
     bitSet(bitsToSend, 1);
  }   
if (digitalRead(inPin2) == HIGH)
  {
     bitSet(bitsToSend, 2);
  }
if (digitalRead(inPin3) == HIGH)
  {
     bitSet(bitsToSend, 3);
  }
if (digitalRead(inPin4) == HIGH)
  {
     bitSet(bitsToSend, 4);
  }
if (digitalRead(inPin5) == HIGH)
  {
     bitSet(bitsToSend, 5);
  }
if (digitalRead(inPin6) == HIGH)
  {
     bitSet(bitsToSend, 6);
  }
if (digitalRead(inPin7) == HIGH)
  {
     bitSet(bitsToSend, 7);
  }

  {

  // Pull Latch Pin LOW before sending data
  digitalWrite(latchPin, LOW);

  // Modify the correct bit:
  bitWrite(bitsToSend, whichPin, whichState);

  // Shift the bits out:
  shiftOut(dataPin, clockPin, LSBFIRST, bitsToSend);

  // Turn on the Latch Pin so the LEDs can light up:
  digitalWrite(latchPin, HIGH);

  }

  Serial.print(digitalRead(inPin0));

  delay(200);

}

Might I suggest using bitWrite() to shorten your repetitive code.

This

bitWrite(bitsToSend, 0, digitalRead(inPin0));
bitWrite(bitsToSend, 1, digitalRead(inPin1));
bitWrite(bitsToSend, 2, digitalRead(inPin2));
bitWrite(bitsToSend, 3, digitalRead(inPin3));
bitWrite(bitsToSend, 4, digitalRead(inPin4));
bitWrite(bitsToSend, 5, digitalRead(inPin5));
bitWrite(bitsToSend, 6, digitalRead(inPin6));
bitWrite(bitsToSend, 7, digitalRead(inPin7));

Replaces

bitsToSend = 0;
  
  // Read the inputs and send HIGH bit values to the corresponding pin on the shift register

if (digitalRead(inPin0) == HIGH)
  {
     bitSet(bitsToSend, 0);
  }
if (digitalRead(inPin1) == HIGH)
  {
     bitSet(bitsToSend, 1);
  }   
if (digitalRead(inPin2) == HIGH)
  {
     bitSet(bitsToSend, 2);
  }
if (digitalRead(inPin3) == HIGH)
  {
     bitSet(bitsToSend, 3);
  }
if (digitalRead(inPin4) == HIGH)
  {
     bitSet(bitsToSend, 4);
  }
if (digitalRead(inPin5) == HIGH)
  {
     bitSet(bitsToSend, 5);
  }
if (digitalRead(inPin6) == HIGH)
  {
     bitSet(bitsToSend, 6);
  }
if (digitalRead(inPin7) == HIGH)
  {
     bitSet(bitsToSend, 7);
  }

stajo:
Thank you for your interest.

I'm afraid I dont have your sharp debug eyes on the 0 pin.

But I have come so far that i have managed to see in the Serial Printer that inPin0 gets recorded by pressing, I also switched some cables to see and it is reacting. The 0 pin on the ShiftRegister doesnt seem to ever go high though, I guess adwsystems has spotted why.

I have also gotten the outputs to turn off when released, thank you for that UKHeliBob.

Actually I was referring to the problem with not going low.

As for bit 0, not being set. Is bit 0 set first or last? If you send 0xFF, what do you get? (delete the input buttons, move all logic to Setup() to run once. What comes out of the shift register?

Thank you adwsystems, you may.

It skinned the cat just as well but with neater code. Looks like same recource allocation.

But it did not solve the inPin0 problem. Where shall I look?

Edit, just spotted more in your post.

//Declaring input pins

byte inPin0 = A0;   // pushbutton connected to analog pin A0
byte inPin1 = A1;   // pushbutton connected to analog pin A1
byte inPin2 = A2;   // pushbutton connected to analog pin A2
byte inPin3 = A3;   // pushbutton connected to analog pin A3
byte inPin4 = A4;   // pushbutton connected to analog pin A4
byte inPin5 = A5;   // pushbutton connected to analog pin A5
byte inPin6 = 2;    // pushbutton connected to digital pin 2
byte inPin7 = 3;    // pushbutton connected to digital pin 3

//Declaring output pins

int latchPin = 6;   //Pin connected to ST_CP(pin 12) of 74HC595
int clockPin = 7;   //Pin connected to SH_CP(pin 11) of 74HC595
int dataPin = 8;    //Pin connected to DS(pin 14) of 74HC595

//Declaring variables for storing the value of each output pin

int whichPin;
int whichState;
byte bitsToSend;

void setup() {
  
  // Declare input variables
  
  pinMode(inPin0, INPUT);        // sets the analog pin A0 as input
  pinMode(inPin1, INPUT);        // sets the analog pin A1 as input
  pinMode(inPin2, INPUT);        // sets the analog pin A2 as input
  pinMode(inPin3, INPUT);        // sets the analog pin A3 as input
  pinMode(inPin4, INPUT);        // sets the analog pin A4 as input
  pinMode(inPin5, INPUT);        // sets the analog pin A5 as input
  pinMode(inPin6, INPUT);        // sets the digital pin 3 as input
  pinMode(inPin7, INPUT);        // sets the digital pin 4 as input

  // Declare Arduino board output pins to 74HC595 input pins:
  
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
  
  // Read the inputs and send HIGH bit values to the corresponding pin
  // on the shift register when inPins go high

bitWrite(bitsToSend, 0, digitalRead(inPin0));
bitWrite(bitsToSend, 1, digitalRead(inPin1));
bitWrite(bitsToSend, 2, digitalRead(inPin2));
bitWrite(bitsToSend, 3, digitalRead(inPin3));
bitWrite(bitsToSend, 4, digitalRead(inPin4));
bitWrite(bitsToSend, 5, digitalRead(inPin5));
bitWrite(bitsToSend, 6, digitalRead(inPin6));
bitWrite(bitsToSend, 7, digitalRead(inPin7));

  {

  //Shifting out the bits to 74HC595

  // Pull Latch Pin LOW before sending data
  digitalWrite(latchPin, LOW);

  // Modify the correct bit:
  bitWrite(bitsToSend, whichPin, whichState);

  // Shift the bits out:
  shiftOut(dataPin, clockPin, LSBFIRST, bitsToSend);

  // Turn on the Latch Pin so the LEDs can light up:
  digitalWrite(latchPin, HIGH);

  delay(200);

  }

}

adwsystems:
As for bit 0, not being set. Is bit 0 set first or last? If you send 0xFF, what do you get? (delete the input buttons, move all logic to Setup() to run once. What comes out of the shift register?

I can for example run this https://www.arduino.cc/en/Tutorial/ShftOut12 example code and lit up diodes 0-7 from serial monitor if that is answering your question? HW exactly the same, comm pins changed to my config in code..

You also changed MSBFIRST TO LSBFIRST. What else has changed?

You are not debouncing any of the input switches. That may also cause an issue. This is one of those cases where it appears to be so simple that nothing can be wrong. So you must go simpler. I suggest you remove the switches and try hard coded values. Have the button load a value into bitsToSend instead of tying the button directly to the variable.

Hmm,

I had tried both MSB and LSB and it just changes the order. On MSB id does not lit up the rightmost, on LSB id does not lit up the leftmost. That excludes led malfunctions.

I can take the lab connect cables and bypass all the buttons, except the first one. Excludes pushbutton malfunction.

All buttons gives signal in Serial monitor for all input pins.

And I can lit every diode with another program.

I exchanged the 75HC595, same result

I changed from A0 to digital 13 on HW and in code, same result, no litting, except for the built in diode on UNO.

It all points toward a code bug to me.

Im not wiz enough to cook an easy software test, you're very welcome to give example code.

//Declaring input pins

byte inPin0 = A0;   // pushbutton connected to analog pin A0
byte inPin1 = A1;   // pushbutton connected to analog pin A1
byte inPin2 = A2;   // pushbutton connected to analog pin A2
byte inPin3 = A3;   // pushbutton connected to analog pin A3
byte inPin4 = A4;   // pushbutton connected to analog pin A4
byte inPin5 = A5;   // pushbutton connected to analog pin A5
byte inPin6 = 2;    // pushbutton connected to digital pin 2
byte inPin7 = 3;    // pushbutton connected to digital pin 3

//Declaring output pins

int latchPin = 6;   //Pin connected to ST_CP(pin 12) of 74HC595
int clockPin = 7;   //Pin connected to SH_CP(pin 11) of 74HC595
int dataPin = 8;    //Pin connected to DS(pin 14) of 74HC595

//Declaring variables for storing the value of each output pin

int whichPin;
int whichState;
byte bitsToSend;

void setup() {
  
  // Declare input variables
  
  pinMode(inPin0, INPUT);        // sets the analog pin A0 as input
  pinMode(inPin1, INPUT);        // sets the analog pin A1 as input
  pinMode(inPin2, INPUT);        // sets the analog pin A2 as input
  pinMode(inPin3, INPUT);        // sets the analog pin A3 as input
  pinMode(inPin4, INPUT);        // sets the analog pin A4 as input
  pinMode(inPin5, INPUT);        // sets the analog pin A5 as input
  pinMode(inPin6, INPUT);        // sets the digital pin 3 as input
  pinMode(inPin7, INPUT);        // sets the digital pin 4 as input

  // Declare Arduino board output pins to 74HC595 input pins:
  
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
  
  // Read the inputs and send HIGH bit values to the corresponding pin
  // on the shift register when inPins go high

bitWrite(bitsToSend, 0, digitalRead(inPin0));
bitWrite(bitsToSend, 1, digitalRead(inPin1));
bitWrite(bitsToSend, 2, digitalRead(inPin2));
bitWrite(bitsToSend, 3, digitalRead(inPin3));
bitWrite(bitsToSend, 4, digitalRead(inPin4));
bitWrite(bitsToSend, 5, digitalRead(inPin5));
bitWrite(bitsToSend, 6, digitalRead(inPin6));
bitWrite(bitsToSend, 7, digitalRead(inPin7));

  {

  //Shifting out the bits to 74HC595

  // Pull Latch Pin LOW before sending data
  digitalWrite(latchPin, LOW);

  // Modify the correct bit:
  bitWrite(bitsToSend, whichPin, whichState);

  // Shift the bits out:
  shiftOut(dataPin, clockPin, LSBFIRST, bitsToSend);

  // Turn on the Latch Pin so the LEDs can light up:
  digitalWrite(latchPin, HIGH);

  delay(200);

  }

}

What are these variables used for and where are they changed?

//Declaring variables for storing the value of each output pin

int whichPin;
int whichState;
byte bitsToSend;

I don't think this is doing what you think it does.

  // Modify the correct bit:
  bitWrite(bitsToSend, whichPin, whichState);

Also, you have an extra pair of curly braces in your loop.

Metallor:
What are these variables used for and where are they changed?

I am not sure. If I dont declare them the compiler complains. Whats the story?

//Declaring variables for storing the value of each output pin

int whichPin;
int whichState;
byte bitsToSend;




I don't think this is doing what you think it does.

Ok thank you, what is the correct statement?

 // Modify the correct bit:
  bitWrite(bitsToSend, whichPin, whichState);

Also, you have an extra pair of curly braces in your loop.

Removed a pair in the loop, was it them you had in mind?

stajo:
I am not sure. If I dont declare them the compiler complains.

If you are not sure what they do, why did you put them there? Try removing the line

bitWrite(bitsToSend, whichPin, whichState);

and see what happens.

Bingo! Thanks alot Metallor and others, now it behaves as it should. I guess the bitWrite line was there since someone recommended me to use bitWrite a few post back. I had to keep the bitsToSend variable, was that as expected?

//Declaring input pins

byte inPin0 = A0;   // pushbutton connected to analog pin A0
byte inPin1 = A1;   // pushbutton connected to analog pin A1
byte inPin2 = A2;   // pushbutton connected to analog pin A2
byte inPin3 = A3;   // pushbutton connected to analog pin A3
byte inPin4 = A4;   // pushbutton connected to analog pin A4
byte inPin5 = A5;   // pushbutton connected to analog pin A5
byte inPin6 = 2;    // pushbutton connected to digital pin 2
byte inPin7 = 3;    // pushbutton connected to digital pin 3

//Declaring output pins

int latchPin = 6;   //Pin connected to ST_CP(pin 12) of 74HC595
int clockPin = 7;   //Pin connected to SH_CP(pin 11) of 74HC595
int dataPin = 8;    //Pin connected to DS(pin 14) of 74HC595

//Declaring variables for storing the value of each output pin

byte bitsToSend;

void setup() {
  
  // Declare input variables
  
  pinMode(inPin0, INPUT);        // sets the analog pin A0 as input
  pinMode(inPin1, INPUT);        // sets the analog pin A1 as input
  pinMode(inPin2, INPUT);        // sets the analog pin A2 as input
  pinMode(inPin3, INPUT);        // sets the analog pin A3 as input
  pinMode(inPin4, INPUT);        // sets the analog pin A4 as input
  pinMode(inPin5, INPUT);        // sets the analog pin A5 as input
  pinMode(inPin6, INPUT);        // sets the digital pin 3 as input
  pinMode(inPin7, INPUT);        // sets the digital pin 4 as input

  // Declare Arduino board output pins to 74HC595 input pins:
  
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
  
  // Read the inputs and send HIGH bit values to the corresponding pin
  // on the shift register when inPins go high

bitWrite(bitsToSend, 0, digitalRead(inPin0));
bitWrite(bitsToSend, 1, digitalRead(inPin1));
bitWrite(bitsToSend, 2, digitalRead(inPin2));
bitWrite(bitsToSend, 3, digitalRead(inPin3));
bitWrite(bitsToSend, 4, digitalRead(inPin4));
bitWrite(bitsToSend, 5, digitalRead(inPin5));
bitWrite(bitsToSend, 6, digitalRead(inPin6));
bitWrite(bitsToSend, 7, digitalRead(inPin7));


  //Shifting out the bits to 74HC595

  // Pull Latch Pin LOW before sending data
  digitalWrite(latchPin, LOW);

  // Shift the bits out:
  shiftOut(dataPin, clockPin, LSBFIRST, bitsToSend);

  // Turn on the Latch Pin so the LEDs can light up:
  digitalWrite(latchPin, HIGH);

  delay(200);

}