Existing accounts (including admin) seeded before new demos shipped had no easy way to pull in the latest copies — the registration-time seeder is intentionally non-destructive. The new badge action fetches src/static/bundled-demos/manifest.json, confirms the overwrite, and re-copies each canonical demo into code/. Open tabs of those files are refreshed in place so the user sees the new content immediately. src/static/bundled-demos/ ships the six canonical files plus the manifest so this works in local mode and on a static-only host. The Dockerfile now mirrors workspace/code/<demo>.py into bundled-demos/ during the image build, keeping the two locations in sync. Co-authored-by: Cursor <cursoragent@cursor.com>
55 lines
1.2 KiB
Python
55 lines
1.2 KiB
Python
"""Pin features demo.
|
|
|
|
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.
|
|
"""
|
|
|
|
import time
|
|
|
|
from machine import Pin, PWM
|
|
|
|
|
|
led_a = Pin(2, Pin.OUT)
|
|
led_b = Pin(4, Pin.OUT)
|
|
button = Pin(0, Pin.IN, Pin.PULL_UP)
|
|
fader = PWM(Pin(13), freq=1000, duty_u16=0)
|
|
|
|
|
|
def on_button(pin):
|
|
print("[irq] button rising edge -> toggling pin 2")
|
|
led_a.toggle()
|
|
|
|
|
|
button.irq(handler=on_button, trigger=Pin.IRQ_RISING)
|
|
|
|
|
|
tick = 0
|
|
duty = 0
|
|
direction = 1024
|
|
|
|
while True:
|
|
led_a.value(tick % 2)
|
|
if tick % 4 == 0:
|
|
led_b.on()
|
|
elif tick % 4 == 2:
|
|
led_b.off()
|
|
|
|
duty += direction
|
|
if duty >= 65535:
|
|
duty = 65535
|
|
direction = -1024
|
|
elif duty <= 0:
|
|
duty = 0
|
|
direction = 1024
|
|
fader.duty_u16(duty)
|
|
|
|
button.value()
|
|
|
|
tick += 1
|
|
time.sleep(0.1)
|