sk6812-client/knightrider.py

47 lines
1.1 KiB
Python
Executable file

#!/usr/bin/env python3
import sk6812
import time
num_modules = 300
interval = 0.05
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 = {}
curModule = [0, 0, 0, 0]
speed = [0.49, 0.65, 1, 0.81]
#countUp = [True, True, False]
while True:
set_colors = {}
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
set_colors[num_modules-1-int(curModule[3])][3] = 255
for k in set_colors.keys():
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):
w.fade_color(i, 0, 0, 0, 0)
w.commit()
for i in range(4):
curModule[i] += speed[i]
if curModule[i] >= num_modules:
curModule[i] -= num_modules
time.sleep(interval)