reading 4x4 keypad with 4 pins and a bidirectional 4 bit shift register 74LS195


To whoever interested : it is possible to read multiple key presses from a 4x4 keypad with only 4 pins using a bidirectional 4-bit shift register 74LS195 :

-connect the 4 parallel output pins Q0, ..., Q3 to the rows of the keypad
-connect the 4 parallel input pins P0, ..., P3 to the columns
-connect the parallel/serial pin, the clock pin, the serial in pin and the last parallel output pin Q3 to the arduino. Declare them as arduino outputs except Q3.

-turn the register in serial input mode throught the parallel vs serial pin
-send 0001 (one bit at a time) to the register through the serial in and clock pins (this will activate one of the rows)
-turn the register in parallel input mode (this will read all the columns at once)
-turn the register in serial input mode
-from pin Q3 and using the clock pin, read one by one the four bits in the register
-do the same thing with 0010, 0100 and 1000 (one can save a little time by injecting the appropriate bits in the register while reading the columns in the previous step)

What makes the thing work well is that the parallel input in the register from pins P0, ..., P3 is instantaeous compared to the time needed to propagate the data to the output pins Q0, ..., Q3.