from machine import Pin
import time
# 定义开关和 LED 引脚
SWITCH_PINS = [Pin(32, Pin.IN, Pin.PULL_UP), Pin(25, Pin.IN, Pin.PULL_UP),
Pin(27, Pin.IN, Pin.PULL_UP), Pin(14, Pin.IN, Pin.PULL_UP)]
LED_PINS = [Pin(5, Pin.OUT), Pin(18, Pin.OUT), Pin(19, Pin.OUT), Pin(21, Pin.OUT)]
# 初始化状态
led_states = [0, 0, 0, 0]
while True:
# 检测开关状态
for i, sw in enumerate(SWITCH_PINS):
if not sw.value():
time.sleep_ms(10) # 消除抖动
if not sw.value():
led_states[i] = not led_states[i]
LED_PINS[i].value(led_states[i])
while not sw.value(): # 等待开关松开
pass
print("郝嘉恒202110733207")