Multistrip versions for Musiclight Mini
This commit is contained in:
parent
0a757fa90f
commit
4122e5bcfc
|
@ -2,12 +2,13 @@
|
||||||
|
|
||||||
import sk6812_multistrip as sk6812
|
import sk6812_multistrip as sk6812
|
||||||
import time
|
import time
|
||||||
|
import sys
|
||||||
|
|
||||||
num_modules = 16
|
num_modules = 16
|
||||||
|
|
||||||
interval = 1/60
|
interval = 1/60
|
||||||
|
|
||||||
w = sk6812.SK6812("192.168.42.1", 2703)
|
w = sk6812.SK6812(sys.argv[1], 2703)
|
||||||
w.set_fadestep(0.20/interval)
|
w.set_fadestep(0.20/interval)
|
||||||
#w.set_num_modules(num_modules)
|
#w.set_num_modules(num_modules)
|
||||||
|
|
||||||
|
@ -29,13 +30,17 @@ while True:
|
||||||
|
|
||||||
set_colors[int(curModule[0])] = [0, 0, 0, 0]
|
set_colors[int(curModule[0])] = [0, 0, 0, 0]
|
||||||
set_colors[int(curModule[1])] = [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[1])] = [0, 0, 0, 0]
|
||||||
set_colors[num_modules-1-int(curModule[3])] = [0, 0, 0, 0]
|
set_colors[int(curModule[2])] = [0, 0, 0, 0]
|
||||||
|
set_colors[int(curModule[3])] = [0, 0, 0, 0]
|
||||||
|
#set_colors[num_modules-1-int(curModule[3])] = [0, 0, 0, 0]
|
||||||
|
|
||||||
set_colors[int(curModule[0])][0] = brightness
|
set_colors[int(curModule[0])][0] = brightness
|
||||||
set_colors[int(curModule[1])][1] = brightness
|
set_colors[int(curModule[1])][1] = brightness
|
||||||
set_colors[num_modules-1-int(curModule[2])][2] = brightness
|
#set_colors[num_modules-1-int(curModule[1])][1] = brightness
|
||||||
set_colors[num_modules-1-int(curModule[3])][3] = brightness
|
set_colors[int(curModule[2])][2] = brightness
|
||||||
|
set_colors[int(curModule[3])][3] = brightness
|
||||||
|
#set_colors[num_modules-1-int(curModule[3])][3] = brightness
|
||||||
|
|
||||||
for strip in range(8):
|
for strip in range(8):
|
||||||
for k in set_colors.keys():
|
for k in set_colors.keys():
|
||||||
|
|
|
@ -10,7 +10,6 @@ from hsv2rgbw import hsv2rgbw
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
s = sk6812.SK6812(sys.argv[1], 2703)
|
s = sk6812.SK6812(sys.argv[1], 2703)
|
||||||
s.set_fadestep(10)
|
|
||||||
|
|
||||||
phase = 0
|
phase = 0
|
||||||
nled = 16
|
nled = 16
|
||||||
|
@ -71,6 +70,7 @@ loop = 0
|
||||||
intensity = MAXENERGY_ADD
|
intensity = MAXENERGY_ADD
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
s.set_fadestep(10)
|
||||||
|
|
||||||
if loop % 5 == 0:
|
if loop % 5 == 0:
|
||||||
intensity = random.randint(MAXENERGY_ADD*3//4, MAXENERGY_ADD*5//4)
|
intensity = random.randint(MAXENERGY_ADD*3//4, MAXENERGY_ADD*5//4)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sk6812_multistrip as sk6812
|
import sk6812_multistrip as sk6812
|
||||||
import time
|
import time
|
||||||
|
@ -19,21 +19,37 @@ strip = 0
|
||||||
|
|
||||||
tiltphase = 0
|
tiltphase = 0
|
||||||
|
|
||||||
|
seq = 0
|
||||||
|
rxseq = 0
|
||||||
|
lasttxtime = 0
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
rxseq = s.try_read_seq()
|
||||||
|
if rxseq != -1:
|
||||||
|
print(f"TX: {seq}, RX: {rxseq}")
|
||||||
|
|
||||||
|
now = time.time()
|
||||||
|
|
||||||
|
if rxseq >= seq - 3 or (lasttxtime < now - 0.5):
|
||||||
|
lasttxtime = now
|
||||||
|
|
||||||
for i in range(nled):
|
for i in range(nled):
|
||||||
for strip in range(nstrip):
|
for strip in range(nstrip):
|
||||||
x = 2*math.pi * i / nled
|
x = 2*math.pi * i / nled
|
||||||
y = 2*math.pi * strip * 2*math.sin(tiltphase) / nstrip
|
y = 2*math.pi * strip * 2*math.sin(tiltphase) / nstrip
|
||||||
r = scale * (127 + 127 * math.sin(y + x + 13*phase + 0 * math.pi/2))
|
r = scale * (127 + 127 * math.sin(y + x + 283*phase + 0 * math.pi/2))
|
||||||
g = scale * (127 + 127 * math.sin(y + x + 23*phase + 1 * math.pi/2))
|
g = scale * (127 + 127 * math.sin(y + x + 293*phase + 1 * math.pi/2))
|
||||||
b = scale * (127 + 127 * math.sin(y + x + 42*phase + 2 * math.pi/2))
|
b = scale * (127 + 127 * math.sin(y + x + 307*phase + 2 * math.pi/2))
|
||||||
w = scale * 0.6 * (127 + 127 * math.sin(y + x + 5*phase + 3 * math.pi/2))
|
w = scale * 0.6 * (127 + 127 * math.sin(y + x + 311*phase + 3 * math.pi/2))
|
||||||
|
|
||||||
s.set_color((strip+5)%nstrip, i, r, g, b, w)
|
s.set_color((strip+0)%nstrip, i, r, g, b, w)
|
||||||
|
|
||||||
|
s.ack_request(seq)
|
||||||
|
seq += 1
|
||||||
s.commit()
|
s.commit()
|
||||||
|
|
||||||
phase += 2*math.pi * interval / 41
|
phase += 2*math.pi * interval / (739*1)
|
||||||
tiltphase += 2*math.pi * interval / 11
|
tiltphase += 2*math.pi * interval / (471/2)
|
||||||
time.sleep(interval)
|
time.sleep(interval)
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
import sk6812_multistrip as sk6812
|
import sk6812_multistrip as sk6812
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
|
import sys
|
||||||
|
|
||||||
s = sk6812.SK6812("192.168.42.1", 2703)
|
s = sk6812.SK6812(sys.argv[1], 2703)
|
||||||
|
|
||||||
phase = 0
|
phase = 0
|
||||||
nled = 16
|
nled = 16
|
||||||
|
|
|
@ -3,22 +3,23 @@
|
||||||
import sk6812_multistrip as sk6812
|
import sk6812_multistrip as sk6812
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
|
import sys
|
||||||
|
|
||||||
num_modules = 16
|
num_modules = 16
|
||||||
num_strips = 8
|
num_strips = 8
|
||||||
|
|
||||||
interval = 1/30
|
interval = 1/20
|
||||||
|
|
||||||
w = sk6812.SK6812("10.42.7.145", 2703)
|
w = sk6812.SK6812(sys.argv[1], 2703)
|
||||||
w.set_fadestep(0.80/interval)
|
|
||||||
|
|
||||||
color = [255, 0, 255, 0]
|
color = [0x20, 0x40, 0x00, 0x10]
|
||||||
|
|
||||||
cur_strip = 0
|
cur_strip = 0
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
w.set_fadestep(int(0.80/interval))
|
||||||
for k in range(num_modules):
|
for k in range(num_modules):
|
||||||
f = math.sin(math.pi * k / num_modules)
|
f = 1#math.sin(math.pi * k / num_modules)
|
||||||
w.add_color(cur_strip, k, f*color[0], f*color[1], f*color[2], f*color[3])
|
w.add_color(cur_strip, k, f*color[0], f*color[1], f*color[2], f*color[3])
|
||||||
|
|
||||||
for strip in range(8):
|
for strip in range(8):
|
||||||
|
|
|
@ -12,6 +12,7 @@ class SK6812Command:
|
||||||
FADE_COLOR = 1
|
FADE_COLOR = 1
|
||||||
ADD_COLOR = 2
|
ADD_COLOR = 2
|
||||||
SET_FADESTEP = 3
|
SET_FADESTEP = 3
|
||||||
|
ACK_REQUEST = 255
|
||||||
|
|
||||||
def __init__(self, action = SET_COLOR, strip = 0, module = 0, d0 = 0, d1 = 0, d2 = 0, d3 = 0):
|
def __init__(self, action = SET_COLOR, strip = 0, module = 0, d0 = 0, d1 = 0, d2 = 0, d3 = 0):
|
||||||
self.action = int(action)
|
self.action = int(action)
|
||||||
|
@ -33,6 +34,7 @@ class SK6812:
|
||||||
family, socktype, proto, canonname, sockaddr = socket.getaddrinfo(host, port, 0, socket.SOCK_DGRAM)[0]
|
family, socktype, proto, canonname, sockaddr = socket.getaddrinfo(host, port, 0, socket.SOCK_DGRAM)[0]
|
||||||
|
|
||||||
self.__socket = socket.socket(family, socktype, proto)
|
self.__socket = socket.socket(family, socktype, proto)
|
||||||
|
self.__socket.settimeout(0.0) # nonblocking mode
|
||||||
self.__socket.connect(sockaddr)
|
self.__socket.connect(sockaddr)
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
|
@ -62,6 +64,21 @@ class SK6812:
|
||||||
# add a "add to color" command
|
# add a "add to color" command
|
||||||
self.__commands.append(SK6812Command(SK6812Command.ADD_COLOR, strip, module, r, g, b, w))
|
self.__commands.append(SK6812Command(SK6812Command.ADD_COLOR, strip, module, r, g, b, w))
|
||||||
|
|
||||||
|
def ack_request(self, seq):
|
||||||
|
# add a "request for acknowledgement" command
|
||||||
|
self.__commands.append(SK6812Command(SK6812Command.ACK_REQUEST, 0, 0, (seq >> 8) & 0xFF, seq & 0xFF, 0, 0))
|
||||||
|
|
||||||
|
def try_read_seq(self):
|
||||||
|
try:
|
||||||
|
data = self.__socket.recv(2)
|
||||||
|
except socket.error:
|
||||||
|
return -1
|
||||||
|
|
||||||
|
if not data or len(data) != 2:
|
||||||
|
return -1
|
||||||
|
else:
|
||||||
|
return struct.unpack(">H", data)[0]
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
w = SK6812("192.168.2.222", 2703)
|
w = SK6812("192.168.2.222", 2703)
|
||||||
w.set_fadestep(1);
|
w.set_fadestep(1);
|
||||||
|
|
Loading…
Reference in a new issue