Repository navigation
Expand file tree
/
Copy pathMerged Test
More file actions
60 lines (48 loc) · 1.74 KB
/
Copy pathMerged Test
File metadata and controls
60 lines (48 loc) · 1.74 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
56
57
58
59
60
import time
from neopixel import *
import skywriter
import signal
from math import ceil
grid_width=12
grid_height=8
# LED strip configuration:
LED_COUNT = 96 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (must support PWM!).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
LED_DMA = 5 # DMA channel to use for generating signal (try 5)
LED_BRIGHTNESS = 50 # Set to 0 for darkest and 255 for brightest
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS)
def xy_to_strip(x, y, strip_len):
return y*strip_len + x
def set_pixel(id, colour):
if id>-10 and id<96:
print str(id)+":"+str(colour)
strip.setPixelColor(id, colour)
print 'id {}, {} '.format(id, colour)
else:
print 'id {}, {} out of range'.format(id, colour)
def set_shape(x, y):
for i in (-2, -1, 0, 1, 2):
for j in (-2, -1, 0, 1, 2):
mode = abs(i)+ abs(j)
if mode == 0:
set_pixel(xy_to_strip(x+i, y+j, 8), Color(250, 200, 200))
if mode == 1:
set_pixel(xy_to_strip(x+i, y+j, 8), Color(250, 0, 100))
if mode == 2:
set_pixel(xy_to_strip(x+i, y+j, 8), Color(100, 0, 100))
if mode == 3:
set_pixel(xy_to_strip(x+i, y+j, 8), Color(50, 0, 50))
if mode == 4:
set_pixel(xy_to_strip(x+i, y+j, 8), Color(25, 0, 25))
strip.begin()
# this handles move events from the skywriter library
@skywriter.move()
def move(x,y,z):
tx = ceil(x * grid_width)
# if up and down are reversed remove the "grid_height - " bit
ty = int(grid_height - ceil(y * grid_height))
set_shape(tx, ty)
strip.show()
signal.pause()