首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >esp8266 - micropython - neopixel当下一个led继续时,如何关闭前一个led?

esp8266 - micropython - neopixel当下一个led继续时,如何关闭前一个led?
EN

Stack Overflow用户
提问于 2021-01-28 01:50:36
回答 1查看 105关注 0票数 0

我在试着让led像秒针一样向前走。

代码语言:javascript
复制
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()

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-28 04:11:52

我不完全清楚你想让你的显示器看起来是什么样子,但这可能会有所帮助。使用下面的代码,“秒”led永远不会覆盖“小时”或“分钟”led。

关键的是,我们还将当前小时、分钟和秒的leds以外的所有内容都重置为"off“。

代码语言:javascript
复制
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测试它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65924608

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档