mechanical key/The board/01. Two circuits, one key
The board · 01 of 9

Two circuits, one key

The TK96 is a keyboard switch with an RGB LED under it, and the two are not connected to each other. The key tells your sketch it was pressed; the LED shows whatever colour your sketch last sent. Anything that links them is code.

The key does not light the light

Two circuits, one key
The key
The sketch has sent
BUTTON reads
HIGH
Key current
0.50 mA
LED
dark
The key is down and BUTTON reads HIGH, and the LED is dark. Nothing on the board joins them: the switch closes a path from VCC through the 10 kΩ resistor to GND, and the LED only changes when 24 bits arrive on its own pin. Your sketch is the wire between them.

Press the key and hold it. BUTTON reads HIGH and the LED stays dark. That surprises people, because on a keyboard with backlighting the light and the key look like one part.

Here they are two circuits side by side. The key is a switch from VCC to BUTTON, with a 10 kΩ resistor from BUTTON to GND: the same circuit as the TK04 Push Button. The light is one WS2812, a red, green and blue LED with its own small controller inside. Its data input is the header's WS2812 pin, and it shows a colour only when 24 bits arrive there. The two share GND and VCC and nothing else.

Why that is the useful way round

Because the sketch sits between them, the light can say something the finger does not already know. A key that lights while it is held tells you that you are holding it. A key that stays red once armed, turns green when a task is done, or blinks while something waits, tells you the state of the program. A key that remembers builds the simplest version: each press moves to the next mode, and the colour is the mode.

What each half costs

The key draws nothing while it is up. Held down, the 10 kΩ carries VCC divided by 10 kΩ: 0.5 mA at 5 V, 0.33 mA at 3.3 V. The LED draws about 0.5 mA dark, and up to 5 mA for each colour at full brightness, so about 15.5 mA at full white. Neither is anything a board's supply notices.

The page this handbook replaces said the key "outputs LOW when pressed". It outputs HIGH, for the reason in Pressed reads HIGH.

When it does not work

I press the key and the LED stays dark.

That is the board working as designed. The switch and the LED share only GND and VCC; pressing the key changes the voltage on BUTTON and nothing else. The LED changes colour when your sketch sends it data on the WS2812 pin.

The LED stays lit after I let go.

A WS2812 keeps the last colour it was sent until it is sent another, or loses power. If your sketch lights it on a press, it also has to send off (all zeros) on the release, as the first press sketch does.

Can I use the key without the LED, or the LED without the key?

Yes. Wire GND and VCC either way, then only the pin you need: BUTTON for the key, WS2812 for the light. The unused half does nothing on its own. An unwired WS2812 pin leaves the LED dark; an unwired BUTTON costs nothing.

Where this goes next

Four parts: the switch, the LED under it, a 10 kΩ resistor and the header. No capacitor.

What is on it →

Edit this page — content/books/mechanical-key/two-circuits-one-key.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Mechanical Key and LED

Loading 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.

Browse Modules and blocks on the forum →