Skip to content

Keyboard API Call Flow

Run MicroSim in Fullscreen

Specification

The full specification below is extracted from Chapter 13: Programming the Pi 500+'s Per-Key RGB Keyboard Lighting.

Type: workflow-diagram
**sim-id:** keyboard-api-call-flow<br/>
**Library:** p5.js<br/>
**Status:** Specified

Learning objective: Students will *analyze* (Bloom L4: Analyze) the layers between a Python lighting effect script and an illuminated key, from the keyboard API down to the firmware.

Canvas: 700x360px, responsive — recompute the four-box horizontal layout as fractions of `width` inside `windowResized()`, stacking vertically below 480px wide.

Layout: four connected boxes left to right: "Your Lighting Effect Script (Python)" → "Python Keyboard Library / Keyboard API (RPiKeyboardConfig)" → "USB HID Protocol (over the USB cable)" → "Keyboard Firmware (sets the physical LED)." Each box uses a distinct color from the book's palette, with a small animated dot traveling left to right along the connecting arrows when triggered.

Controls: a `createButton()` labeled "Trace set_led_by_matrix() Call" that animates the dot traveling through all four boxes in sequence, pausing briefly at each one.

Interaction: clicking any box (independent of the animated trace) opens an infobox with a one-sentence explanation of that layer's job, matching the chapter's prose. A small always-visible caption below the diagram reads "Your script never talks to the firmware directly — the keyboard API is the layer that makes that safe and simple."

Implementation: p5.js. Store boxes as an array of `{label, x, width, color, definition}` objects. Animate the trace dot with linear interpolation between box centers over a fixed duration per segment, triggered by the button and paused at each box for a short dwell time. Rectangle-based hit-testing in `mousePressed()` for the static click interaction.