1 Star 0 Fork 0

Walkline/MicroPython WS2812 Digital Effect

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.py 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
"""
Copyright © 2024 Walkline Wang (https://walkline.wang)
Gitee: https://gitee.com/walkline/micropython-ws2812-digital-effect
"""
from random import randint, choice
from time import sleep_ms
from ws2812 import WS2812
from config import Config
from effects.effect1 import DigitalEffect1
# from effects.effect2 import DigitalEffect2
from effects.effect3 import DigitalEffect3
def random_generator(max):
while True:
yield randint(0, max)
def run_test():
leds = WS2812(Config.Matrix.WIDTH, Config.Matrix.HEIGHT, Config.Pin.DIN)
effects = (DigitalEffect1(leds), DigitalEffect3(leds))
numbers = random_generator(9)
directions = random_generator(3)
leds.clean()
leds.show()
last_value_1 = last_value_2 = 0
while True:
value = next(numbers)
effect = choice(effects)
effect.last_value = last_value_1
if isinstance(effect, DigitalEffect3):
effect.show(value, 1, 0, next(directions))
else:
effect.show(value, 1, 0)
last_value_1 = value
value = next(numbers)
effect = choice(effects)
effect.last_value = last_value_2
if isinstance(effect, DigitalEffect3):
effect.show(value, 5, 0, next(directions))
else:
effect.show(value, 5, 0)
last_value_2 = value
sleep_ms(200)
if __name__ == '__main__':
run_test()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/walkline/micropython-ws2812-digital-effect.git
git@gitee.com:walkline/micropython-ws2812-digital-effect.git
walkline
micropython-ws2812-digital-effect
MicroPython WS2812 Digital Effect
master

搜索帮助