"""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)