Maximum number of SN74HC165N

  • For the 'index + 1' / 'numbered from zero' thing:
#define number_of_74hc595s 20
#define numOfRegisterPins number_of_74hc595s *8
boolean registers[numOfRegisterPins];

numOfRegisterPins is 160.
Here you have declared registers as 160 booleans.
They are numbered registers[0] ... registers[159].
registers[160] does not exist. (Reading it will give you garbage, writing to it can cause all kinds of weirdness.)

Look closely at your writeRegisters() function. There is a for-loop.

  • On storing 8 bits in a byte instead of 1:

I'm not going to walk you through that. Look into 'bitwise operators'.
For now you should not focus on that.

  • On turning that block into a single line: (you should not focus on this either, but here goes: )

For example, the 'index' variable.
You assign 'i' to 'index', and then pass 'index' to some function. You might as well pass 'i' directly. This gets rid of 'index' altogether.
In the same way, you assign HIGH or LOW to a variable, and then pass that variable to a function. You might as well pass HIGH or LOW directly and get rid of that variable too.
But we can go further.. The test in the 'if' compares something to HIGH. Something that can only be HIGH or LOW .. ..which is the only difference between the if-block and else-block.

if (x == HIGH)
{
  bla(HIGH);
}
else
{
  bla(LOW);
}

is the same as

bla(x);

Focus on the 1st point, about the zero based array index and the for-loop in your writeRegisters() function. And then on implementing your own logic for how the outputs respond to the inputs.

Thanks again!!!

Thanks Herodes for building this and Jobi-Wan for the appropriate help and self-help motivation.. reading this helped me understand a lot.

blender-:
Thanks Herodes for building this and Jobi-Wan for the appropriate help and self-help motivation.. reading this helped me understand a lot.

Pleased to have helped you, friend!