Here's a link to a 4 I/O pin method of reading 12 buttons. Easily
expandable to 16 once you go thru it and understand how it works.
http://www.mikerj.clara.net/keypad.html
The web site incorrectly says that 7 i/o lines are needed when
no external components are added other than the switches. In
the NxM topolgy, that's true. But in the simplex topology, only
6 i/o lines are needed to cover up to 15 switches without
diodes. So the situation isn't quite as bad as postulated.
However, it's interesting for a number of reasons -- when I/O is
tight and lots of diodes are okay -- but also because it's
modeled with binomials:
I/O Binomial Matrix Usable Required
Pins Pattern Columns Switches Diodes
3 1 2 1 3 9 6
4 1 3 3 1 7 28 16
5 1 4 6 4 1 15 75 40
and so on. The number of matrix columns is taken from the sum
of values on each rank, minus 1 (the first value.)
The numbers on each rank of the binomial means something like
this: "How many unique ways can you read <I> zeros back on the
available input lines," where <I> is 0 for the first value, 1
for the second, and so on. For example, on the rank for four
I/O pins, that reads as, "1 way to uniquely read no zeros back
on 3 input lines, 3 ways to uniquely read one zero back on 3
inputs, 3 ways to uniquely read two zeroes back on 3 inputs, and
1 way to uniquely read back three zeroes on 3 inputs." Only the
first one, the one asking about how many ways to read back
nothing at all (always 1 way) isn't useful for making a switch
column, because it's the same as "no key press."
If you arrange the diodes so that you can achieve each of these
patterns, for each possible active line, the number of usable
switches will be the number of I/O lines times the number of
columns.
If N is the number of I/O pins, then:
Columns = [2^(N-1) - 1]
Switches = N*[2^(N-1) - 1]
Diodes = N*[2^(N-2)]
To illustrate an example not shown on that web page, but which
shows how these patterns extend, here's the example for 5 I/O
lines:
-----------x-----x---x-x-x-x-x-x-------------,
---------x-----x---x---x-x-x-x---x---------, |
-------x-----x-----x-x---x-x---x-x-------, | |
-----x-------x-x-x-------x---x-x-x-----, | | |
-----x-x-x-x---------------x-x-x-x---, | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
O-O-O-O-O-O-O-O-O-O-O-O-O-O-O---' | | | |
| | | | | | | | | | | | | | | | | | |
O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-----' | | |
| | | | | | | | | | | | | | | | | |
O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-------' | |
| | | | | | | | | | | | | | | | |
O-O-O-O-O-O-O-O-O-O-O-O-O-O-O---------' |
| | | | | | | | | | | | | | | |
O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-----------'
The 'x' values show the diode connections that the particular
column makes.
The ratio of diodes to switches rapidly approaches 1/2. Of
course, only one key press at a time for this scheme and often a
handful of diodes.
Thanks for the site!
Jon