esp8266 - micropython - neopixel。当下一个前进时,我如何关闭前一个 LED?

esp8266 - micropython - neopixel. how i can turn off previous led when next one go forward?

我正在努力让 led 像二手货一样前进。

np = neopixel.NeoPixel(machine.Pin(2), led)
while True:
    t = utime.localtime()
    h = int(utime.localtime()[3]) + time_zone
    m = utime.localtime()[4]
    s = utime.localtime()[5]
    np[h] = (64, 64, 64)
    np[m] = (64, 64, 64)
    np[s] = (64, 64, 64)#turn on
    time.sleep(1)
    sc = s - 1
    np[sc] = (0, 0, 0)#turn off
    np.write()

但我认为我的代码不是一个好主意。

我不太清楚您希望显示的外观如何,但也许这会有所帮助。使用下面的代码,“秒”指示灯将永远不会覆盖“小时”或“分钟”指示灯。

重要的是,除了我们在当前小时、分钟和秒内点亮的 LED,我们还将所有内容重置为“关闭”。

import machine
import neopixel

# on my micropython devices, 'time' and 'utime' refer to the same module
import time

np = neopixel.NeoPixel(machine.Pin(2), 60)

while True:
    t = time.localtime()
    h, m, s = (int(x) for x in t[3:6])

    # set everything else to 0
    for i in range(60):
        np[i] = (0, 0, 0)

    np[s] = (0, 0, 255)
    np[m] = (0, 255, 0)
    np[h] = (255, 0, 0)

    np.write()
    time.sleep(0.5)

我自己没有 neopixel,所以我写了一个 simulator 用于用常规 Python.

测试它