Two keys at once
Press two keys and I2CKeyPad returns FAIL rather than guess. A plain scanner would report them — and with three keys in an L it would also report a fourth that nobody pressed.
One line, or it is not a key
The library's two reads each expect exactly one of four pins to come back 0. A second key pulls a second pin low in one of the reads, and that pattern is not one of the four. So getKey() returns 17, FAIL, and getChar() prints the F at position 17 of the keymap.
Hold two keys, then switch the reader to a scanner. Try three keys in an L — 1, 2 and 5.
The fourth key
With the scanner, three keys in an L light a fourth crossing. Keypads like these have no diode per key — the soft one is two printed films with nowhere to put one — so current can run backwards through a pressed key: from the driven column, up one held key, along a row, down another held key and into a second row. The empty corner's row and column end up joined, and a scanner cannot tell that from a press. This is called ghosting.
Keyboards that must read many keys at once put a diode on every key to stop it. A PIN pad normally does without.
Why FAIL is the better answer
A keypad for codes and menus wants one key at a time. Refusing anything else is honest: the library never reports a key that was not pressed. The cost is chords — no Shift-plus-key — and for a keypad with sixteen keys that is rarely a loss.
In practice the F shows up for a moment when somebody types fast and presses the next key before releasing the last. A sketch that ignores F and N and prints only when the answer changes never shows it.
Bounce
A key's contacts do not close cleanly: they touch, part and touch again for a few milliseconds. Reading every 20 ms is slower than the bounce, so each read sees either a settled press or a settled release. The sketches here do that. If a key still registers twice, read less often: 50 ms is still far quicker than anybody types.
When it does not work
The next key went down before the last one came up, so for a moment two keys were held. The sketches in this book ignore F and N and print only when the answer changes, so the new key prints as soon as the old one is released.
This keypad and library cannot do that reliably. Use one key as a mode switch instead — press * to enter a second layer, the next key is read in that layer — or use two keypads at two addresses.
The contacts bounce for a few milliseconds as they close. Reading every 20 ms and printing only on a change hides it; if a key still doubles, read less often by changing the sketch's delay(20) to delay(50).
Two keypads on one board: three pads, eight addresses, and pull-ups that add up.
More than one keypad →Edit this page — content/books/matrix-keypad/two-keys-at-once.mdx
Questions about this product
See what other owners have asked, and read their solutions.
This page covers several products. Choose yours to see the right discussions.
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.