代码拉取完成,页面将自动刷新
"""
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()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。