-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_neopixels.py
77 lines (61 loc) · 1.53 KB
/
test_neopixels.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
"""
DiscoPie programmed, designed, and 3D printed by Benjamin Chase for Baked Dessert Cafe and Gallery
Copyright (c) 2022 pythoncoder8888
All code is licensed under the MIT License
See LICENSE.txt for more details
"""
import os
import time
import RPi.GPIO as GPIO
import board
import neopixel
import random
pixel_pin = board.D12
num_pixels = 40
ORDER = neopixel.GRB
pixel_brightness = 0.1
color_list = [(255, 0, 0), (252, 104, 5), (255, 255, 0), (0, 255, 0), (0, 0, 255), (255, 0, 255)]
pixels = neopixel.NeoPixel(
pixel_pin, num_pixels, brightness=pixel_brightness, auto_write=False, pixel_order=ORDER
)
for i in range(num_pixels):
pixels[i] = (0,255,0)
pixels.show()
time.sleep(0.1)
time.sleep(2)
pixels.fill((0, 0, 0))
GPIO.setmode(GPIO.BCM)
global current_color
current_color = 0
def rainbow(colors, length):
global current_color
for j in range(num_pixels):
pixels[j] = colors[current_color]
pixels.show()
time.sleep(length)
current_color = current_color + 1
if current_color > 5:
current_color = 0
try:
while True:
rainbow(color_list, 0.05)
except KeyboardInterrupt:
pixels.fill((0, 255, 0))
pixels.show()
time.sleep(1.5)
for i in range(num_pixels):
pixels[-i] = (0, 0, 0)
pixels.show()
time.sleep(0.1)
pixels.fill((0, 0, 0))
pixels.show()
print("\nQuit by user")
GPIO.cleanup()
exit()
except Exception as e:
pixels.fill((0, 0, 0))
pixels.show()
time.sleep(5)
print(e)
pass
GPIO.cleanup()