-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplay_color_led.py
executable file
·65 lines (50 loc) · 1.34 KB
/
display_color_led.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
#!/usr/bin/python
#
# Update BlinkyTape LED's on the command line
#
# Usage: python display_color_led.py {red/green/yellow/blue/blank/white} [ {red/green/yellow/blue/blank/white} [ {red/green/yellow/blue/blank/white} ... ] ]
#
import time
import urllib
import json
import tempfile
import sys
import colorsys
import os
import glob
import BlinkyTape
def connect():
serialPorts = glob.glob("/dev/ttyACM**")
if not serialPorts:
sys.exit("Could not locate a BlinkyTape.")
port = serialPorts[0]
print "BlinkyTape found at: %s" % port
bt = BlinkyTape.BlinkyTape(port)
bt.displayColor(0, 0, 0)
return bt
color_map = {
'red': (255, 0, 0),
'green': (0, 255, 0),
'yellow': (255, 255, 0),
'blue': (0, 0, 255),
'blank': (0, 0, 0),
'white': (255, 255, 255),
}
def adjust_color(color, dim_factor=0.10):
r, g, b = color
h, s, v = colorsys.rgb_to_hsv(r / 256.0, g / 256.0, b / 256.0)
r, g, b = colorsys.hsv_to_rgb(h, s, v * dim_factor)
return int(r * 256), int(g * 256), int(b * 256)
if __name__ == "__main__":
bt = connect()
for color in sys.argv[1:]:
print("sending color: %s" % color)
c = color_map[color]
print("c: ")
print(c)
c = adjust_color(c)
print("c: ")
print(c)
r, g, b = c
bt.sendPixel(r, g, b)
bt.show()