Prototyping a keyboard matrix

Build a key matrix with a diode on every key, watch it scanned, and try layers, an encoder and per-key RGB before you solder.

The template

Key matrix numpad is twelve tactile switches in four rows and three columns on a Pro Micro, one half-size breadboard per row of keys. Each switch straddles its board's channel so its left legs carry the column down the stack; its right legs go through a 1N4148 onto the row. Rows are on pins 2 to 5 and columns on 8, 7 and 6. A rotary encoder and a strip of twelve WS2812B LEDs, one per key, complete it.

Open it from /templates, or take the course on /learn: Custom keyboards from the matrix up.

Diode direction

The template is wired COL2ROW, as QMK names it: rows are driven LOW one at a time, columns are read with pull-ups, and each diode's band (the cathode) faces the row. Fit a diode the other way around and its key never reads.

The course also has a 4 x 4 membrane keypad with no diodes at all, where three keys on a rectangle make a ghost fourth.

What the sketch does

The keymatrix sketch scans the matrix, debounces each key for 5 ms, and looks each press up in a keymap with three layers: NUM, a numpad; NAV, held on the bottom-left key; and EDIT, toggled from NAV. A transparent key (____) falls through to the layer below. The knob scrolls the mouse wheel on NUM and sends keys on the other layers. Pushing the knob turns the lighting off and on.

It is a readable Arduino sketch, not QMK or KMK. Use it to prove the matrix, the pins and the layout, then put the same facts into the firmware you flash.

What the computer would see

Mokxi does not simulate the USB link to a computer. The Keyboard and Mouse libraries print each report to the Serial Monitor instead:

[Keyboard] press Up
[Mouse] move x 0 y 0 wheel 1

The Keyboard library sends the standard six-key report, so a seventh key held at once is refused, as on a real board.

The Pro Micro in Mokxi and sim racing and flight sim controllers, which use the same board as a game controller.