sk6812-client/knightrider.py

47 lines
1.1 KiB
Python
Raw Normal View History

2019-12-01 14:21:01 +01:00
#!/usr/bin/env python3
2019-12-01 14:21:01 +01:00
import sk6812
import time
2019-12-01 14:21:01 +01:00
num_modules = 300
2019-12-01 14:21:01 +01:00
interval = 0.05
2019-12-01 14:21:01 +01:00
w = sk6812.SK6812("zybot", 2703)
w.set_fadestep(0.05/interval)
w.set_num_modules(num_modules)
# dictionary which maps {module: [r, g, b]}
set_colors = {}
2019-12-01 14:21:01 +01:00
curModule = [0, 0, 0, 0]
speed = [0.49, 0.65, 1, 0.81]
#countUp = [True, True, False]
while True:
set_colors = {}
2019-12-01 14:21:01 +01:00
set_colors[int(curModule[0])] = [0, 0, 0, 0]
set_colors[int(curModule[1])] = [0, 0, 0, 0]
set_colors[num_modules-1-int(curModule[2])] = [0, 0, 0, 0]
set_colors[num_modules-1-int(curModule[3])] = [0, 0, 0, 0]
set_colors[int(curModule[0])][0] = 255
set_colors[int(curModule[1])][1] = 255
set_colors[num_modules-1-int(curModule[2])][2] = 255
2019-12-01 14:21:01 +01:00
set_colors[num_modules-1-int(curModule[3])][3] = 255
for k in set_colors.keys():
2019-12-01 14:21:01 +01:00
w.add_color(k, set_colors[k][0], set_colors[k][1], set_colors[k][2], set_colors[k][3])
for i in range(num_modules):
2019-12-01 14:21:01 +01:00
w.fade_color(i, 0, 0, 0, 0)
w.commit()
2019-12-01 14:21:01 +01:00
for i in range(4):
curModule[i] += speed[i]
if curModule[i] >= num_modules:
curModule[i] -= num_modules
time.sleep(interval)