-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlights.py
73 lines (59 loc) · 1.86 KB
/
lights.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
#!/usr/bin/env python3
# Wrapper for making the lights run.
import time
from neopixel import *
import logging as log
import sys
led_width = 10
led_height = 20
led_count = led_width * led_height
led_pin = 18
led_freq_hz = 800000
led_dma = 5
led_invert = False
led_brightness = 64
colors = [
[0, 0, 0], # 0 - Black
[255, 255, 255], # 1 - White
[255, 0, 0], # 2 - Red
[0, 255, 0], # 3 - Green
[0, 0, 255], # 4 - Blue
[255, 128, 0], # 5 - Orange
[255, 0, 255], # 6 - Purple
[0, 255, 255], # 7 - Cyan
]
def strip_pos_to_board(led_num):
xpos = int(led_num % led_height)
ypos = int(led_num / led_height)
if ypos % 2 == 0:
xpos = led_height - xpos - 1
ypos = led_width - ypos - 1
return (xpos, ypos)
class Board(object):
def __init__(self):
"""Setup a board"""
self.strip = Adafruit_NeoPixel(led_count, led_pin, led_freq_hz, led_dma, led_invert, led_brightness)
self.strip.begin()
def show_board(self, board):
"""Show a board on the lights"""
for led in range(led_count):
xpos, ypos = strip_pos_to_board(led)
try:
led_rgb = colors[board['pixels'][xpos][ypos]]
except IndexError:
log.error("Ivalid color ID %s", board['pixels'][xpos][ypos])
led_rgb = [255, 255, 255]
led_color = Color(led_rgb[0], led_rgb[1], led_rgb[2])
self.strip.setPixelColor(led, led_color)
self.strip.show()
def main():
strip = Adafruit_NeoPixel(led_count, led_pin, led_freq_hz, led_dma, led_invert, led_brightness)
strip.begin()
colour = Color(64, 128, 64)
for i in range(strip.numPixels()):
strip.setPixelColor(i, colour)
strip.show()
time.sleep(10/1000.0)
if __name__ == "__main__":
main()
sys.exit(0)