from machine import Pin
import time
# LED 設在 GP2
led = Pin(2, Pin.OUT)
# 按鈕設在 GP15,使用內建下拉電阻
button = Pin(15, Pin.IN, Pin.PULL_DOWN)
while True:
if button.value() == 1: # 按下
led.value(1) # LED 亮
else: # 放開
led.value(0) # LED 滅
time.sleep(0.01)