Skip to content

Power Mode and Battery Life Simulator

Run MicroSim in Fullscreen

Specification

The full specification below is extracted from Chapter 9: Real-Time Clocks and Display Drivers for Clocks and Watches.

Type: microsim
**sim-id:** power-mode-battery-life-simulator<br/>
**Library:** p5.js<br/>
**Template:** https://github.com/dmccreary/microsims/tree/main/docs/sims/battery-life<br/>
**Status:** Specified

Learning objective: Students will *evaluate* (Bloom L5: Evaluate) the tradeoff between clock update interval and estimated battery life across active, sleep, and deep sleep power modes.

Canvas: 700x420px, responsive -- recompute the current-draw bar chart and estimated-life readout layout from `windowWidth` in `windowResized()`.

Layout: a horizontal bar chart showing simulated current draw (in milliamps, on a log-scaled axis) for three power modes -- Active, Sleep, Deep Sleep -- as three colored bars (raspberry red for Active, copper gold for Sleep, circuit green for Deep Sleep). Beneath the chart, a large readout displays "Estimated battery life: [X days, Y hours]" computed from the currently selected mix of modes and a fixed coin-cell capacity assumption.

Controls: a `createSlider()` labeled "Clock Update Interval (seconds)" (range 1-60, default 5) controlling how often the simulated device wakes from sleep mode into active mode to redraw; a `createSlider()` labeled "Percent Time in Deep Sleep" (range 0-95, default 0) representing how much of each day the watch spends in deep sleep (e.g., overnight) rather than cycling between active and sleep; a `createButton()` labeled "Reset to Always-On" that sets update interval to 1 second and deep-sleep percentage to 0, showing the worst-case battery life for comparison.

Interaction: moving either slider immediately recalculates and animates the estimated-battery-life readout counting up or down to its new value, and the three bars' relative heights update to reflect the new time-weighted average current draw. Hovering any bar shows a tooltip with that mode's approximate current draw in milliamps and one sentence describing when a real watch would use it, matching the surrounding chapter text. Clicking "Reset to Always-On" animates the readout dropping sharply, visually demonstrating just how much battery life sleep and deep sleep recover.

Implementation: p5.js, battery life estimated with a simple weighted-average formula: total current draw = (active fraction x active mA) + (sleep fraction x sleep mA) + (deep-sleep fraction x deep-sleep mA), then estimated hours = assumed battery capacity (mAh) / total current draw (mA). Active fraction derived from the update-interval slider (shorter interval means proportionally more time active). Recompute chart and text layout from `windowWidth` in `windowResized()`.