-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFunctions.py
More file actions
55 lines (50 loc) · 1.7 KB
/
Functions.py
File metadata and controls
55 lines (50 loc) · 1.7 KB
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
from neopixel import Color
def set_pixel(strip, id, colour):
if id>-10 and id<96:
strip.setPixelColor(id, colour)
print 'id {}, {} '.format(id, colour)
else:
print 'id {}, {} out of range'.format(id, colour)
def set_shape(strip, x, y, width, height):
for i in (-3, -2, -1, 0, 1, 2, 3):
for j in (-3, -2, -1, 0, 1, 2, 3):
mode = abs(i)+ abs(j)
if mode == 0:
color = Color(250, 200, 200)
if mode == 1:
color = Color(250, 0, 100)
if mode == 2:
color = Color(100, 0, 100)
if mode == 3:
color = Color(50, 0, 50)
if mode == 4:
color = Color(25, 0, 25)
if mode == 5:
color = Color(10, 0, 10)
if 0 <= x+i <= width and 0 <= y+j <= height:
set_pixel(strip, xy_to_strip(x+i, y+j, 8), color)
def pulse(q, strip, width, height):
forward = 1
brightness = 0
loc = [0, 0, 0] #loc[0] = X, loc[1] = Y, loc[2] = STEP
color = Color(0, 0, 0)
for i in range(strip.numPixels()):
strip.setPixelColor(i, color)
strip.show()
while True: #This loops every 10ms, so led matrix is updated smoothly.
if q.empty() is False:
loc = q.get_nowait()
#print loc
if forward is 1:
brightness = brightness + loc[2]
else:
brightness = brightness - loc[2]
if brightness <= 0:
forward = 1
brightness = 0
if brightness >= 255:
forward = 0
brightness = 255
set_shape(strip, loc[0], loc[1], width, height)
def xy_to_strip(x, y, strip_len):
return x * strip_len + y