-
Notifications
You must be signed in to change notification settings - Fork 1
/
lightMode.py
288 lines (252 loc) · 8.8 KB
/
lightMode.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import time
from rpi_ws281x import PixelStrip, Color
import sys
# LED 燈條的設定值
LED_COUNT = 111 # 燈泡數量
LED_PIN = 18 # 訊號輸出的 GPIO 腳位
LED_FREQ_HZ = 800000
LED_DMA = 10
LED_BRIGHTNESS = 255 # 燈光亮度
LED_INVERT = False
LED_CHANNEL = 0
iterations = 20 # 循環次數, 規定以下的燈光模式偶爾會用到
# 預設的燈光模式, 一個一個點亮燈
def colorWipe(color):
for i in range(strip.numPixels()):
strip.setPixelColor(i, color)
strip.show()
time.sleep(50 / 1000.0)
# 預設的燈光模式
def theaterChase(strip, color, wait_ms=50, iterations=10):
for j in range(iterations):
for q in range(3):
for i in range(0, strip.numPixels(), 3):
strip.setPixelColor(i + q, color)
strip.show()
time.sleep(wait_ms / 1000.0)
for i in range(0, strip.numPixels(), 3):
strip.setPixelColor(i + q, 0)
# 預設的燈光模式
def wheel(pos):
if pos < 85:
return Color(pos * 3, 255 - pos * 3, 0)
elif pos < 170:
pos -= 85
return Color(255 - pos * 3, 0, pos * 3)
else:
pos -= 170
return Color(0, pos * 3, 255 - pos * 3)
# 預設的燈光模式
def rainbow(strip, wait_ms=20, iterations=1):
for j in range(256 * iterations):
for i in range(strip.numPixels()):
strip.setPixelColor(i, wheel((i + j) & 255))
strip.show()
time.sleep(wait_ms / 1000.0)
# 預設的燈光模式
def rainbowCycle():
for j in range(256 * iterations):
for i in range(strip.numPixels()):
strip.setPixelColor(i, wheel((int(i * 256 / strip.numPixels()) + j) & 255))
strip.show()
time.sleep(50 / 1000.0)
# 預設的燈光模式
def theaterChaseRainbow(wait_ms=50):
for j in range(256):
for q in range(3):
for i in range(0, strip.numPixels(), 3):
strip.setPixelColor(i + q, wheel((i + j) % 255))
strip.show()
time.sleep(wait_ms / 1000.0)
for i in range(0, strip.numPixels(), 3):
strip.setPixelColor(i + q, 0)
# 一次亮所有顏色
def oneColor(color):
for i in range(strip.numPixels()):
strip.setPixelColor(i, color)
strip.show()
def creepy():
# print("creepy")
for j in range(260 * iterations, 250 * iterations, -1):
for i in range(strip.numPixels()):
strip.setPixelColor(i, wheel((i + j) & 255))
strip.show()
time.sleep(50 / 1000.0)
for j in range(250 * iterations, 260 * iterations):
for i in range(strip.numPixels()):
strip.setPixelColor(i, wheel((i + j) & 255))
strip.show()
time.sleep(50 / 1000.0)
def newyear():
# print("newYear")
for j in range(iterations):
for q in range(3):
for i in range(0, strip.numPixels(), 4):
strip.setPixelColor(i + q, Color(255, 119, 0))
strip.setPixelColor(i + 1 + q, Color(255, 0, 2))
strip.show()
time.sleep(700 / 1000.0)
for i in range(0, strip.numPixels(), 3):
strip.setPixelColor(i + 2, 0)
strip.setPixelColor(i + 3, 0)
strip.show()
def birthday():
# print("Birthday")
for i in range(0, strip.numPixels(), 2):
strip.setPixelColor(i, Color(239, 255, 0))
strip.setPixelColor(i + 1, Color(18, 255, 10))
strip.show()
time.sleep(2)
for i in range(1, strip.numPixels(), 2):
strip.setPixelColor(i, Color(18, 255, 10))
strip.setPixelColor(i + 1, Color(239, 255, 0))
strip.show()
time.sleep(1)
def fuck():
# print("fuck")
for j in range(125 * iterations, 135 * iterations, 0.5):
for i in range(strip.numPixels()):
strip.setPixelColor(i, wheel((i + j) & 255))
strip.show()
time.sleep(200 / 1000.0)
for i in range(strip.numPixels()):
oneColor(Color(0, 0, 0))
strip.show()
time.sleep(200 / 1000.0)
for j in range(135 * iterations, 125 * iterations, -0.5):
for i in range(strip.numPixels()):
strip.setPixelColor(i, wheel((i + j) & 255))
strip.show()
time.sleep(200 / 1000.0)
for i in range(strip.numPixels()):
oneColor(Color(0, 0, 0))
strip.show()
time.sleep(200 / 1000.0)
def thePurge():
# print("thePurde")
oneColor(Color(255, 0, 0)) #紅
time.sleep(2)
oneColor(Color(0, 0, 0)) #紅
time.sleep(2)
def fierce():
# print("fierce")
for j in range(iterations):
for q in range(3):
for i in range(0, strip.numPixels(), 3):
strip.setPixelColor(i + q, Color(255, 0, 111))
strip.setPixelColor(i + 1 + q, Color(205, 0, 255))
strip.show()
time.sleep(100 / 1000.0)
for i in range(0, strip.numPixels(), 3):
strip.setPixelColor(i + 2, 0)
strip.show()
def party():
print("party")
for j in range(iterations):
for q in range(3):
for i in range(0, strip.numPixels(), 3):
strip.setPixelColor(i + q, Color(255, 90, 0))
strip.setPixelColor(i + 1 + q, Color(77, 0, 255))
strip.setPixelColor(i + 2 + q, Color(0, 255, 134))
strip.setPixelColor(i + 3 + q, Color(205, 0, 255))
strip.show()
time.sleep(200 / 1000.0)
for i in range(0, strip.numPixels(), 3):
strip.setPixelColor(i + q, 0)
def relax():
# print("relax")
for j in range(210 * iterations, 200 * iterations, -1):
for i in range(strip.numPixels()):
strip.setPixelColor(i, wheel((i + j) & 255))
strip.show()
time.sleep(50 / 1000.0)
for j in range(200 * iterations, 210 * iterations):
for i in range(strip.numPixels()):
strip.setPixelColor(i, wheel((i + j) & 255))
strip.show()
time.sleep(50 / 1000.0)
def sleep():
# print("sleep")
for j in range(50 * iterations, 30 * iterations, -1):
for i in range(strip.numPixels()):
strip.setPixelColor(i, wheel((i + j) & 255))
strip.show()
time.sleep(300 / 1000.0)
for j in range(30 * iterations, 50 * iterations):
for i in range(strip.numPixels()):
strip.setPixelColor(i, wheel((i + j) & 255))
strip.show()
time.sleep(300 / 1000.0)
def Christmas():
# print("christmas")
for j in range(iterations):
for q in range(3):
for i in range(0, strip.numPixels(), 3):
strip.setPixelColor(i + q, Color(255, 68, 0))
strip.setPixelColor(i + 1 + q, Color(239, 255, 0))
strip.setPixelColor(i + 2 + q, Color(255, 255, 255))
strip.show()
time.sleep(500 / 1000.0)
for i in range(0, strip.numPixels(), 3):
strip.setPixelColor(i + q, 0)
def startWerewolf():
# print("startWerewolf")
for j in range(50 * iterations, 20 * iterations, -1):
for i in range(strip.numPixels()):
strip.setPixelColor(i, wheel((i + j) & 255))
strip.show()
time.sleep(50 / 1000.0)
for j in range(20 * iterations, 50 * iterations):
for i in range(strip.numPixels()):
strip.setPixelColor(i, wheel((i + j) & 255))
strip.show()
time.sleep(50 / 1000.0)
def slasher():
# print("slasher")
for i in range(strip.numPixels()):
oneColor(0, 205, 255)
strip.show()
time.sleep(300 / 1000)
for i in range(strip.numPixels()):
oneColor(0, 0, 0)
strip.show()
time.sleep(200 / 1000)
def conan():
# print("conan")
colorWipe(Color(84, 255, 250))
time.sleep(600 / 1000.0)
colorWipe(Color(0, 0, 0))
time.sleep(600 / 1000.0)
def werewolf():
# print("werewolf")
colorWipe(Color(255, 0, 10))
def witch():
# print("witch")
colorWipe(Color(196, 0, 255))
def predictor():
# print("predictor")
colorWipe(Color(0, 255, 154))
def breakingDawn():
# print("breakingDawn")
colorWipe(Color(255, 219, 97))
# 關燈
def turnOff():
# print("關燈")
for i in range(strip.numPixels()):
strip.setPixelColor(i, 0)
strip.show()
def main(argv):
# 燈光模式清單
lightMode = [creepy, relax, party, startWerewolf, sleep,
Christmas, newyear, thePurge, slasher, fuck,
fierce, birthday, conan, turnOff, theaterChaseRainbow,
turnOff, thePurge, werewolf, witch, predictor,
breakingDawn]
while True:
lightMode[int(argv[0])]()
if __name__ == "__main__":
# 定義燈條
strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
strip.begin()
# 讀入參數(燈光模式)
main(sys.argv[1:])