-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtl7.py
executable file
·160 lines (136 loc) · 3.42 KB
/
tl7.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env python3
import sys
import board
import neopixel
import time
import random
if len(sys.argv) > 1:
num_lights = int(sys.argv[1])
else:
num_lights = 50
print(f'num_lights is {num_lights}')
seg_length = 10
# transform between RGB color and GBR
# goes both ways since it just swaps the first two of the tuple
def t(c):
return (c[1], c[0], c[2])
black = (0, 0, 0)
white = (255, 255, 255)
def sleep(seconds):
time.sleep(seconds)
def slowOn(x):
c = randomColor(x)
delay = .005
#for y in range(256):
#for y in range(128):
for y in range(64):
#print(f'y is {y}')
pc = float((y*4)+1) / 64.0
#print(f'pc is {pc}')
#c2 = (int(pc * c[0]), int(pc * c[1]), int(pc * c[2]))
c2 = (pc * c[0], pc * c[1], pc * c[2])
#print(f'c2 is {c2}')
#time.sleep(delay * (1-pc))
pixels[x] = c2
def setLights(str):
for n in range(len(str)):
pixels[n] = str[n]
# program 50 lights with the default brightness 1.0, and autoWrite true
#pixels = neopixel.NeoPixel(board.D18, num_lights)
# following did not do what I thought it would
#pixels = neopixel.NeoPixel(board.D18, num_lights, pixel_order=neopixel.RGBW)
pixels = neopixel.NeoPixel(board.D18, num_lights)
# set first LED to green
#pixels[0] = (255, 0, 0, 0)
#pixels.fill(black)
#print('red')
#pixels[0] = t((255, 0, 0))
#sleep(1)
#print('green')
#pixels[0] = t((0, 255, 0))
#sleep(1)
#print('blue')
#pixels[0] = t((0, 0, 255))
#sleep(1)
#pixels.fill(black)
# light 20 bright green
#pixels[19] = t((0,255,0))
# light all pixels red
#pixels.fill(t((255,0,0)))
# turn off neopixels
pixels.fill(black)
# green, red, blue
# red, green, blue
# Colors must be supplied to pixels as grb colors,
# but I think in rgb.
# green, red, blue colors translated from rgb
black = t(( 0, 0, 0))
blue = t((000, 000, 255))
red = t((255, 0, 0))
magenta = t((255, 0, 255))
green = t(( 0, 255, 0))
cyan = t(( 0, 255, 255))
yellow = t((255, 255, 000))
white = t((255, 255, 255))
purple = t((75, 0, 130))
#pixels.fill(black)
#print('red')
#pixels[0] = red
#sleep(1)
#print('green')
#pixels[0] = green
#sleep(1)
#print('blue')
#pixels[0] = blue
#sleep(1)
#pixels.fill(black)
colors = [
white,
red,
green,
blue,
yellow,
purple,
magenta,
cyan,
black
]
def randomColor(x):
#return (colors[0])
r = random.randint(0,5)
#print (f'r is: {r}')
return colors[r] # "christmas light colors"
#not reached at the moment
if (x % 2 == 0):
return colors[random.randint(0,5)]
return (random.randint(0,255),random.randint(0,255),random.randint(0,255))
#for x in range(1000):
# pixels.fill(randomColor(x))
# sleep(.010)
while True:
str = []
print(type(str))
for n in range(num_lights):
print(f'n is: {n}')
rc = randomColor(n)
print(f'rc is: {rc}')
str.append(rc)
setLights(str)
for n in range(100):
r = random.randint(0,len(str)-1)
slowOn(r)
pixels.fill(black)
# not reached
delay = 0.04
while True:
for x in range(num_lights+seg_length):
# print(f'setting light {x} to a color')
if (x < num_lights):
pixels[x] = randomColor(x)
# print(f'x is {x}')
if ((x >= num_lights) or (x >= seg_length)):
# print(f'setting light {x-seg_length} to black')
pixels[x-seg_length] = black
sleep(delay)
sleep(1)
pixels.fill((0,0,0))