Pull-Up and Pull-Down Resistor Explorer¶
Specification¶
The full specification below is extracted from Chapter 3: Breadboard Wiring and Electrical Fundamentals.
Type: interactive-diagram
**sim-id:** pull-up-pull-down-resistor-explorer<br/>
**Library:** p5.js<br/>
**Status:** Specified
Learning objective: Students will *compare* (Bloom L4: Analyze) pull-up and pull-down resistor configurations and predict a digital pin's default and pressed-state reading for each.
Canvas: 700x400px, responsive — recompute the two circuit-diagram panel widths as fractions of `windowWidth` inside `windowResized()`, stacking vertically below 500px.
Layout: two side-by-side simple circuit diagrams, left labeled "Pull-Up Configuration" showing a resistor drawn between a VCC rail and a GPIO pin node, with a button drawn between that same node and ground; right labeled "Pull-Down Configuration" showing the mirrored arrangement (resistor to ground, button to VCC). Each pin node displays its current reading ("HIGH" or "LOW") as a colored badge (green for HIGH, gray for LOW).
Controls: a `createButton()` on each panel labeled "Press Button," which the student holds (mouse-down) to simulate a button press and releases to return to the resting state.
Interaction: pressing and holding the button on either panel updates that panel's pin-reading badge in real time, and a running text log beneath each panel records the transition (e.g., "Pull-up: resting HIGH -> pressed LOW"). A "Show Floating Pin" toggle button removes both resistors from a third, smaller comparison panel and animates the pin's reading flickering randomly between HIGH and LOW to illustrate why an unconnected digital pin is unpredictable, tying directly back to the chapter's floating-pin warning.
Implementation: p5.js. Represent each panel's circuit state with a simple boolean (`buttonPressed`) and a resistor-mode enum (`pullUp`, `pullDown`, `floating`). Use `mousePressed()`/`mouseReleased()` on each button's bounding box to toggle `buttonPressed`, and `random()` calls gated by `frameCount` to drive the floating-pin flicker only when that mode is active.