> Van: Seth Fischer > Aan: PICLIST@MITVMA.MIT.EDU > Onderwerp: 4x4 keypad routine > Datum: woensdag 11 november 1998 10:50 Hello Seth, > Thanks a lot to all those people who answer my questions. > > I am at the planing stage of writing a program to read in a value from a > 4x4 matrix scan keypad. > > I have got the basics of it (I think, open to suggestions): > i.e. write to column 1000 > read from rows 0100 > result 10000100 > > -Is this an efficient way to do it? I think you will have to invert all bit's, because not connected inputs will result in reading a One. So, it will be Write to column 0111 Read from Rows 1011 Result 01111011 Without any external hardware ? Yes, it is. > -Would the next step be to use a lookup table to obtain a more relevant > value for than key pressed, i.e. 00000001 = 1 etc. Both nibbles should have only _one_ bit clear. Convert the bit-position to a number (0 to 3) and combine both nibbles to a single 4 bit number. the number than tell's you the key-index. after this the look-up table is only 16 bytes (one entry for every Key-index). > -How would I deal with two keys pressed at the same time (seems > impossible)? No, it's not (but hey, I still think that cooking a good meal is impossible to me too :-). I take it that you want to _ignore_ multiple key's down. Write all Zero's. The result should be a single bit clear as a result. switch the Output to Input and vice-verse. Do the above again (write all Zero's). The result should again be a single bit clear. If not, there are multiple/no keys pressed. Oh, by the way : If you want to do the above the Outputs should be Open-collector types (Real or Emulated), and any column/row should be pulled-up by a resistor. Greetz, Rudy Wieser