LED Circuit Builder¶
Specification¶
The full specification below is extracted from Chapter 3: Breadboard Wiring and Electrical Fundamentals.
Type: microsim
**sim-id:** led-circuit-builder<br/>
**Library:** p5.js<br/>
**Template:** https://github.com/dmccreary/moving-rainbow/tree/main/docs/sims/current-predictor<br/>
**Status:** Specified
Learning objective: Students will *apply* (Bloom L3: Apply) the current-limiting resistor formula to build a safe LED circuit, and *analyze* (Bloom L4: Analyze) what happens to current and LED lifespan when the resistor is too small, too large, or missing entirely.
Canvas: 700x460px, responsive — recompute the circuit-diagram area and control-panel width from `windowWidth` inside `windowResized()`, stacking controls beneath the diagram below 550px.
Data Visibility Requirements:
Stage 1: Show a simple series circuit diagram -- VCC rail, resistor, LED (drawn with anode/cathode legs labeled), ground rail -- with the resistor's current value in ohms and the LED's forward voltage and rated current printed as fixed reference numbers.
Stage 2: Show a live calculation panel updating `I = (Vsupply - Vforward) / R` with the current slider/input values substituted in, displayed as a real numeric result in milliamps.
Stage 3: Show the LED rendered in the diagram glowing at a brightness proportional to current when current is at or below the rated value, flashing red with a small "Overcurrent!" label when current exceeds the rated value, and unlit when current is below a visibility threshold.
Controls: a `createSlider()` for resistor value (range 0-500 ohms, default 220), a `createSelect()` for LED color (Red: 2.0V forward voltage, Blue: 3.0V forward voltage, White: 3.0V forward voltage), and a `createSlider()` for supply voltage (range 0-3.3V, default 3.3V, representing the Pico's GPIO output).
Interaction: moving the resistor slider below the calculated safe minimum immediately triggers the overcurrent visualization described in Stage 3, along with a text explanation referencing the current-limiting-resistor formula from the chapter. Setting the resistor slider to 0 simulates the no-resistor case explicitly, with a distinct warning message: "No current-limiting resistor -- this would damage the LED."
Instructional Rationale: A parameter-exploration pattern is appropriate for this Apply-level objective because it lets students test the formula's boundary conditions (too little resistance, zero resistance) safely and see the numeric and visual consequence of each choice, reinforcing why the calculation -- not guesswork -- determines a safe resistor value.
Implementation: p5.js. Recalculate current every frame from current slider/dropdown state using the Ohm's Law-derived formula, map current to LED brightness with `map()` for values under the rated current, and switch to a flashing overcurrent state using `frameCount % n` when current exceeds it. Parent the canvas to the enclosing `<div>` and use `createButton()`/`createSlider()`/`createSelect()` exclusively per project convention for all controls.