sk6812-client/knightrider.py

44 lines
933 B
Python
Raw Normal View History

#!/usr/bin/env python
import ws2801
import time
num_modules = 20
interval = 0.1
w = ws2801.WS2801("192.168.23.222", 2703)
w.set_fadestep(1.0/interval)
# dictionary which maps {module: [r, g, b]}
set_colors = {}
curModule = [0, 0, 0]
speed = [0.49, 0.65, 1]
#countUp = [True, True, False]
while True:
set_colors = {}
set_colors[int(curModule[0])] = [0, 0, 0]
set_colors[int(curModule[1])] = [0, 0, 0]
set_colors[num_modules-1-int(curModule[2])] = [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
for k in set_colors.keys():
w.add_color(k, set_colors[k][0], set_colors[k][1], set_colors[k][2])
for i in range(num_modules):
w.fade_color(i, 0, 0, 0)
w.commit()
for i in range(3):
curModule[i] += speed[i]
if curModule[i] >= num_modules:
curModule[i] -= num_modules
time.sleep(interval)