diff --git a/src/static/bundled-demos/pin_demo.py b/src/static/bundled-demos/pin_demo.py index d63aa68..8d4ce1e 100644 --- a/src/static/bundled-demos/pin_demo.py +++ b/src/static/bundled-demos/pin_demo.py @@ -2,11 +2,12 @@ A "Pins" panel appears below the editor while this script runs: - * Pin 2 (OUT) — blinks every 200 ms; the indicator follows along. - * Pin 4 (OUT) — chases through .on() / .off() / .toggle(). - * Pin 0 (IN) — click the toggle button in the panel to flip its value. - When it goes 0 -> 1 we register an IRQ that toggles pin 2. - * Pin 13 (PWM) — duty sweeps up and down; the bar shows the live duty cycle. + * Pin 2 (OUT) — blinks automatically every ~200 ms via ``.value(...)``. + * Pin 4 (OUT) — stays put until you press the button, then flips + (driven from the IRQ handler with ``.toggle()``). + * Pin 0 (IN) — click the toggle button in the panel to drive a 0 → 1 + rising edge; the IRQ fires and flips pin 4. + * Pin 13 (PWM) — duty sweeps up and down; the bar shows the live duty. """ import time @@ -21,8 +22,9 @@ fader = PWM(Pin(13), freq=1000, duty_u16=0) def on_button(pin): - print("[irq] button rising edge -> toggling pin 2") - led_a.toggle() + # Pin 4 is IRQ-driven on purpose — its only source of change is the + # button press, so when you see it flip you know the IRQ fired. + led_b.toggle() button.irq(handler=on_button, trigger=Pin.IRQ_RISING) @@ -33,12 +35,10 @@ duty = 0 direction = 1024 while True: + # Pin 2: fast on/off via direct .value(...) writes (no IRQ involvement). led_a.value(tick % 2) - if tick % 4 == 0: - led_b.on() - elif tick % 4 == 2: - led_b.off() + # Pin 13: triangular duty sweep so the PWM bar visibly fills and drains. duty += direction if duty >= 65535: duty = 65535 @@ -48,6 +48,8 @@ while True: direction = 1024 fader.duty_u16(duty) + # Poll the IN pin so its IRQ actually fires when the panel button changes. + # (`.value()` reads the current state and dispatches any pending edge.) button.value() tick += 1 diff --git a/src/static/index.html b/src/static/index.html index 45e470e..f55663c 100644 --- a/src/static/index.html +++ b/src/static/index.html @@ -6,7 +6,7 @@