-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathampi.py
93 lines (73 loc) · 2.33 KB
/
ampi.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import adafruit_dotstar as dotstar
import board
import random
import pygame.time
import pygame.camera
import pygame
import os
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
os.environ["DISPLAY"] = ":0"
DEVICE = '/dev/video0'
SIZE_CAPTURE = (640, 480)
X = 41
Y = 24
SIZE_LED = (X, Y)
pixelArray = ()
MIN_BRIGTHNESS = 8
OFFSET = 2
def isPixekBlack(pixelColorRgb):
if pixelColorRgb[0] <= MIN_BRIGTHNESS and pixelColorRgb[1] <= MIN_BRIGTHNESS and pixelColorRgb[2] <= MIN_BRIGTHNESS:
isBlack = True
else:
isBlack = False
return isBlack
def blackLevelCorrection(pixelArray):
for idx, pixelColorRgb in enumerate(pixelArray):
if isPixekBlack(pixelColorRgb):
pixelArray[idx] = (0, 0, 0)
return pixelArray
def ampilight():
try:
pixelArray = dotstar.DotStar(
board.SCK, board.MOSI, X + 2 * Y, brightness=0.3, auto_write=False, baudrate=20000000)
pixelArray.fill((0, 0, 0))
pygame.init()
pygame.camera.init()
camera = pygame.camera.Camera(DEVICE, SIZE_CAPTURE)
screen = pygame.surface.Surface(SIZE_CAPTURE)
tiny = pygame.surface.Surface((10, 5))
pixelMatrix = pygame.surface.Surface(SIZE_LED)
camera.start()
while True:
camera.get_image(screen)
pygame.transform.smoothscale(screen, (10, 5), tiny)
pygame.transform.smoothscale(tiny, SIZE_LED, pixelMatrix)
# right panel
if True:
idx = 0
for y in range(Y-1):
pixelArray[idx] = pixelMatrix.get_at(
(X-1-OFFSET, Y-1-y))[:3]
idx += 1
# top panel
if True:
idx = 23
for x in range(X):
pixelArray[idx] = pixelMatrix.get_at((X-1-x, OFFSET))[:3]
idx += 1
# left panel
if True:
idx = 64
for y in range(Y-1):
pixelArray[idx] = pixelMatrix.get_at((0+OFFSET, y+1))[:3]
idx += 1
pixelArray = blackLevelCorrection(pixelArray)
pixelArray.show()
finally:
print('stopping ...')
pixelArray.fill((0, 0, 0))
camera.stop()
pygame.quit()
return
if __name__ == '__main__':
ampilight()