from machine import Pin
import time
# 定義LED燈的GPIO引脚編號
LedPins = [23, 22, 21, 19, 18, 5, 17, 16, 4, 0]
# 初始化LED引脚,設置為輸出模式
leds = [Pin(pin, Pin.OUT) for pin in LedPins]
def control_leds(index):
"""
根據索引來控制單一LED
:param index: 要開啟LED的索引位置,從0到len(LedPins)-1
"""
# 關閉所有LED
for led in leds:
led.off()
# 開啟指定索引的LED
leds[index].on()
# 循環控制每一個LED
while True:
for i in range(len(LedPins)):
control_leds(i)
time.sleep(0.5)