How are the buttons connected to the 74HC165s?
If it starts to go 'random' when you press several buttons, that sounds like you're short-circuiting the system or something. Measure the voltage at Vcc, does it droop?
The buttons are connected how the should be connected (like on the schematic) . I'm sure that it isn't a hardware problem, because like I said there isn't any problem in detecting multiple buttons, if I connect the arduino only to the second oder first 74hc165 without daisy chaining.
But as soon as I daisy chain two 74HC165 I can't detect multiple buttons from the second 74HC165 that isn't directly connected to arduino.
@PaulRB: Ok, I changed the code and I'm now using the standard shiftIn functions:
switchVar1 = shiftIn(dataPin, clockPin,MSBFIRST);
switchVar2 = shiftIn(dataPin, clockPin, MSBFIRST);
I still get the exact same behavior.
I have 10k resistors between vcc, button and 74HC165 input.
Are there pullups on the shift register inputs so they consistently read high with no button push, and low with a button push?
You should also have 0.1uF caps from Vcc to Gnd on both parts.
Altho personally I would use SPI.transfer, avoid all the software nonsense. Got built in hardware, use it!
I don't want to use SPI. I also get a constant high with no button pushes and a 0 with a press, yes.
Here is an image:
If I press two buttons connected to the first 74HC165 the output is correctly:
11101011 // buttons connected to the first 74HC165, which is connected to the arduino.
11111111 // buttons connected to the second 74HC165, which is daisy chained to the first one.
If I press two buttons connected to the first 74HC165 and one button connected to the second the output is correctly:
If I press two buttons connected to the first 74HC165 and two button connected to the second the output is wrong:
11111011 or 11011011 etc. It cycles trough wrong values…