2.ESP32_LED流水灯
"""
LED流水的实验,四个LED灯
2022.10.9
"""
from machine import Pin
import time
led_pin=[2,3,4,5]#定义GPIO口,设置为输出模式,输入模式为Pin.IN
leds=[]#led列表,保存管脚配置对象
for i in range(4):
leds.append(Pin(led_pin[i],Pin.OUT))
#leds=[Pin(led_pin[i],Pin.OUT) for i in range(0,4)]
if __name__=="__main__":
for n in range(4):#初始化0
leds[n].value(0)
#逐个点亮
while True:
for n in range(4):
leds[n].value(1)
time.sleep(0.25)
#逐个熄灭
for n in range(4):
leds[n].value(0)
time.sleep(0.25)