forked from pburakov/hack_week_py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_matrix.py
59 lines (46 loc) · 1.49 KB
/
test_matrix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import time
import pygame
from neopixel import *
from config import *
from utils import get_serial_pixel
DELAY_SECONDS = 0.1
# Init preview screen
if not NO_PREVIEW:
pygame.display.set_mode((SCREEN_X * P_MFACTOR, SCREEN_Y * P_MFACTOR))
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT,
LED_BRIGHTNESS, LED_CHANNEL, LED_STRIP)
strip.begin()
def update_screen(data):
for y in range(SCREEN_Y):
for x in range(SCREEN_X):
(r, g, b) = get_rgb(data, (x, y))
set_pixel_color((x, y), (r, g, b))
if not NO_PREVIEW:
pygame.display.get_surface().set_at((x * P_MFACTOR, y * P_MFACTOR), (r, g, b))
strip.show()
if not NO_PREVIEW:
pygame.display.flip()
pygame.event.get()
def set_pixel_color(point, color):
x,y = point
r,g,b = color
i = get_serial_pixel(x, y, SCREEN_Y)
strip.setPixelColor(i, Color(r, g, b))
def get_rgb(data, point):
x,y = point
try:
(r, g, b) = data[y][x]
except:
r, g, b = 0, 0, 0
return r, g, b
if __name__ == '__main__':
for x in range(SCREEN_X):
for y in range(SCREEN_Y):
data = [[0] * SCREEN_X for i in range(SCREEN_Y)]
try:
print("Displaying ({}, {})".format(y, x))
data[y][x] = (255, 255, 255)
update_screen(data)
except:
print("failed on pixel ({}, {})".format(y, x))
time.sleep(0.5)