2016-10-12 23:50:00 +02:00
|
|
|
from __future__ import print_function
|
2016-12-25 04:37:43 +01:00
|
|
|
from __future__ import division
|
2016-12-27 10:13:02 +01:00
|
|
|
from __future__ import unicode_literals
|
2016-10-12 23:50:00 +02:00
|
|
|
import socket
|
|
|
|
import numpy as np
|
2016-10-14 07:27:45 +02:00
|
|
|
import config
|
|
|
|
|
|
|
|
_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
2016-11-08 02:44:23 +01:00
|
|
|
_gamma = np.load(config.GAMMA_TABLE_PATH)
|
2016-11-13 10:10:44 +01:00
|
|
|
_prev_pixels = np.tile(253, (3, config.N_PIXELS))
|
2016-10-14 07:27:45 +02:00
|
|
|
|
2016-11-13 10:10:44 +01:00
|
|
|
pixels = np.tile(1, (3, config.N_PIXELS))
|
2016-10-14 07:27:45 +02:00
|
|
|
"""Array containing the pixel values for the LED strip"""
|
|
|
|
|
|
|
|
|
|
|
|
def update():
|
|
|
|
global pixels, _prev_pixels
|
2016-12-29 23:51:38 +01:00
|
|
|
pixels = np.clip(pixels, 0, 255).astype(int)
|
2016-11-08 02:44:23 +01:00
|
|
|
p = _gamma[pixels] if config.GAMMA_CORRECTION else np.copy(pixels)
|
2016-12-31 19:06:09 +01:00
|
|
|
m = []
|
2016-10-14 07:27:45 +02:00
|
|
|
for i in range(config.N_PIXELS):
|
|
|
|
# Ignore pixels if they haven't changed (saves bandwidth)
|
2016-11-13 10:10:44 +01:00
|
|
|
if np.array_equal(p[:, i], _prev_pixels[:, i]):
|
2016-10-14 07:27:45 +02:00
|
|
|
continue
|
2016-12-31 19:06:09 +01:00
|
|
|
m.append(i) # Index of pixel to change
|
|
|
|
m.append(p[0][i]) # Pixel red value
|
|
|
|
m.append(p[1][i]) # Pixel green value
|
|
|
|
m.append(p[2][i]) # Pixel blue value
|
2016-11-12 00:51:41 +01:00
|
|
|
_prev_pixels = np.copy(p)
|
2016-12-31 19:06:09 +01:00
|
|
|
_sock.sendto(bytes(m), (config.UDP_IP, config.UDP_PORT))
|
2016-10-14 07:27:45 +02:00
|
|
|
|
|
|
|
|
2016-12-31 06:18:56 +01:00
|
|
|
# Execute this file to run a LED strand test
|
|
|
|
# If everything is working, you should see a red, green, and blue pixel scroll
|
|
|
|
# across the LED strip continously
|
2016-10-12 23:50:00 +02:00
|
|
|
if __name__ == '__main__':
|
2016-12-31 06:18:56 +01:00
|
|
|
import time
|
|
|
|
# Turn all pixels off
|
2016-12-25 04:37:43 +01:00
|
|
|
pixels *= 0
|
2016-12-31 06:18:56 +01:00
|
|
|
pixels[0, 0] = 255 # Set 1st pixel red
|
|
|
|
pixels[1, 1] = 255 # Set 2nd pixel green
|
|
|
|
pixels[2, 2] = 255 # Set 3rd pixel blue
|
|
|
|
print('Starting LED strand test')
|
|
|
|
while True:
|
|
|
|
pixels = np.roll(pixels, 1, axis=1)
|
|
|
|
update()
|
|
|
|
time.sleep(0.2)
|