I am thinking about writing a library for matrix keypads with a little twist: the columns are driven by shift registers and there will be leds besides the keypad that can be turned on to indicate custom status.
So for example if someone wants 16 keys on a keypad, they need 4 columns and 4 rows so a total of 8 I/O pins. But on the other hand, only row pins need to be input and column pins are all output. If I make a 8 column by 2 row key pad (physically it can be 4 row by 4 column but electrically connected so that the first two rows are connected so are the last two rows) and use a shift register to drive the 8 columns, I only need 3 pins for the shift register and 2 pins for rows, so only 5 pins instead of 8 pins. Plus, with the shift register, I can hook up a number of leds and relays to do simple indications and controls.
I can see this quite useful in a panel I am designing but is there any general interest of such a library? Any suggestions what format of function calls to do? Maybe try to mock the function calls of the keypad lib in playground? Could be useful to construct some homemade illuminated keypads as well.
I think I'd be concerned about it being responsive enough.
How about a 2-output to 4-pin demux to drive a column at a time instead?
And then a 4-input to 2-pin mux to read the row connections back?
I was doing some testing yesterday with only 6 keys and it appeared ok, no significant lag. I will expand my code to sense 16 keys (although I only hooked up 6) and see how long it takes to sense all keys. I could devise a smarter way to keep looking at most recently activated keys and sense them first. I would try demux and mux but I don't have any of them so will have to purchase them next time I stock up parts.
Just realized that my design can only work if one key is pressed at a time per row. If two keys are pressed in the same row and only one is being sensed, there will be a short between these two columns. I guess only I/O pins can avoid that by setting the columns not being sensed to input with internal pullup resistor and only setting one column pin to output LOW at a time. This way multiple key presses can be detected without shorting any circuit. Well, with a simple pad I don't really expect ctrl+alt+del type of input so should be OK.