我在试着让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()但我认为我的代码不是一个好主意。
发布于 2021-01-28 04:11:52
我不完全清楚你想让你的显示器看起来是什么样子,但这可能会有所帮助。使用下面的代码,“秒”led永远不会覆盖“小时”或“分钟”led。
关键的是,我们还将当前小时、分钟和秒的leds以外的所有内容都重置为"off“。
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测试它。
https://stackoverflow.com/questions/65924608
复制相似问题