from machine import Pin, Timer
pins = [15, 18, 27, 13, 21, 25, 5, 19, 22, 12, 14, 26]
leds = [Pin(pin, Pin.OUT) for pin in pins]
timer = Timer(-1)
half_len = len(pins) // 2
led_status = [0] * len(pins) # 记录每个LED的状态,0表示关闭,1表示亮起
def toggle_led(timer):
global led_status
# 交替亮灭LED
for i in range(len(leds)):
if i < half_len:
led_status[i] = not led_status[i]
else:
led_status[i] = not led_status[i - half_len]
if led_status[i]:
leds[i].on()
else:
leds[i].off()
timer.init(period=500, mode=Timer.PERIODIC, callback=toggle_led)