header

How do you optimize the electronic circuit of a keyboard ? It has
- $N$ keys $\{n_0,...n_{N-1}\}$
- a micro-controller with $P$ pins $\{p_0,...p_{P-1}\}$
- you wish to dinstinguish any $K$ key combination

A pin can be in any of the following $4$ states : $\{W_+,W_0,R_+,R_0\}$ that are read and write for +3V or ground.

A button has $2$ connectors that can be either connected or disconnected depending on the press state.

Any $K$ combination means we need at least $∑_{k=1}^{K}\frac{N!}{k!(N-k)!}$ possible states for the micro-controller pins (with some constraints as any pin could be R or W, you need at least one R pin)

Pins have $4^{P}$ states but $2^{P}$ correspond to "no read pins" states. We have at maximum $4^{P} - 2^{P}$ exploitable states

P=
Kmax=
Nmax=
dispay count=

What happens when $P=2$ ? Here is the list of all possible state for the micro-controller. To make notation compact, I will denote $(p_0=W_+,p_1=R_-)$ simply as $(W_+,R_-)$ $$\al{ (W_+,R_+) &&&& (R_+,W_+) &&&& (R_+,R_+) &&&& \cancel{(W_+,W_+)} \\ (W_-,R_+) &&&& (R_+,W_-) &&&& (R_+,R_-) &&&& \cancel{(W_+,W_-)} \\ (W_+,R_-) &&&& (R_-,W_+) &&&& (R_-,R_+) &&&& \cancel{(W_-,W_+)} \\ (W_-,R_-) &&&& (R_-,W_-) &&&& (R_-,R_-) &&&& \cancel{(W_-,W_-)} \\ }$$ which makes 12 states.

What are the values for $K$ and $N$ for which we can make a keyboard ?