I need to read a very basic 3x4 numeric keypad connected directly to my pi. I've read some and decided to go with the so-called shifting-zero algorithm: have 4 pins connected to the keyboard's rows and configured as outputs and another 3 pins connected to the columns configured as inputs, with the internal pull-up resistors enabled. The reading loop would then look something like:
foreach (outputPins as row => outPin) {
set outPin low
foreach (inputPins as column => inPin) {
if (inPin is low) // key at [row][column] is pressed
}
set outPin high
}
(sorry for the pseudo-code ;-) )
There's more logic inside the inner loop related to debouncing the keys etc, but that doesn't directly relate to the question. Because it seems to me that if I press two keys in the same column at the same time, then setting one of the key's corresponding row pin low would effectively short the other key's corresponding row pin (which, in the meantime, is high) to ground. That, I believe, could damage my pi. Or could it? I can't really tell :-) I'm not terribly experienced at this stuff.
I was thinking about connecting a small resistor, say 470R, in series between each output pin and it's corresponding keyboard row. But that wouldn't solve the problem, because if I then press two keys at the same time, the two resistors (along with the internal pull-up) would then form a voltage divider which would cause the input to see something around 1.65V (3.3V / 2) which I don't believe it would really like. Even if it did, it wouldn't read anything useful, which would kind of defeat the whole purpose.
I figure maybe it could be done with diodes then: instead of a resistor, I'd connect a 4148 or the like between each output pin and it's row, it's cathode to the pi, anode to the keyboard. That way the diode disables any current from flowing from the output pins, but still would permit those pins to sink current. But a diode needs some voltage across it to open (typically 0.7V I believe). I think that that's ok as the input pins would have their internal pull-ups enabled thus providing the required voltage, but then the inputs would still see 0.7V instead of 0.. or would they? And if they do, would that still read as a "low"?
Or is there another solution which I'm completely unaware of? O.o
Thanks for any tips!