-
Notifications
You must be signed in to change notification settings - Fork 1
/
lightfantastic-calibrate
executable file
·123 lines (100 loc) · 2.72 KB
/
lightfantastic-calibrate
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/python3
#
# lightfantastic
# https://github.com/anfractuosity/lightfantastic
#
import time
import random
import argparse
from lightfantastic.ids import *
from neopixel import *
LEDs = []
def tree(strip, wait_ms=100):
for i in range(strip.numPixels()):
v = LEDs[i].get()
if v == 0:
col = Color(0, 0, 0)
else:
col = Color(255, 255, 255)
strip.setPixelColor(i, col)
strip.show()
time.sleep(wait_ms / 1000.0)
# Main program logic follows
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="CLI for lightfantastic calibration lights")
parser.add_argument(
"--wait",
dest="wait",
nargs="?",
const=1,
type=int,
default=100,
help="Wait time in milliseconds",
)
parser.add_argument(
"--count",
dest="count",
nargs="?",
const=1,
type=int,
default=100,
help="Number of LEDs",
)
parser.add_argument(
"--pin",
dest="pin",
nargs="?",
const=1,
type=int,
default=18,
help="GPIO pin connected to the pixels",
)
parser.add_argument(
"--freq",
dest="freq",
nargs="?",
const=1,
type=int,
default=800000,
help="LED signal frequency in hertz, usually 800000",
)
parser.add_argument(
"--dma",
dest="dma",
nargs="?",
const=1,
type=int,
default=10,
help="DMA channel to use for generating signal",
)
parser.add_argument(
"--brightness",
dest="brightness",
nargs="?",
const=1,
type=int,
default=2,
help="Brightness of LEDs Set to 0 for darkest and 255 for brightest, a low value is recommended for calibration",
)
parser.add_argument(
"--invert",
dest="invert",
nargs="?",
default=False,
help="To invert the signal (when using NPN transistor level shift)",
)
args = parser.parse_args()
LED_INVERT = not (args.invert == False)
for i in range(args.count):
LEDs.append(IDs(i))
print("Using: %d LEDs, Pin: %d, Freq: %d Hz, DMA: %d, Invert: %r, Brightness: %d, Wait: %d ms"
% ( args.count, args.pin, args.freq, args.dma, LED_INVERT, args.brightness, args.wait ))
# Create NeoPixel object with appropriate configuration.
strip = Adafruit_NeoPixel(
args.count, args.pin, args.freq, args.dma, LED_INVERT, args.brightness
)
# Intialize the library (must be called once before other functions).
strip.begin()
print("Press Ctrl-C to quit.")
while True:
tree(strip,args.wait)