-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (49 loc) · 1.7 KB
/
main.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
from button import Button
from collections import OrderedDict
from leds import Leds
import random
import time
PIN_NUM = 18
BRIGHTNESS = 0.1
LED_GROUPS = OrderedDict([('ring0', 12),
('ring1', 12),
('ring2', 12),
('ring3', 12),
('strip', 72)])
BUTTON_PIN_NUMS = ((12, 13), (14, 15), (16, 17), (19, 20))
def demo(buttons, leds):
# Button LED flash
for _ in range(10):
for button in buttons:
button.led_toggle()
time.sleep(0.1)
# Button LED chase
for _ in range(5):
for button in buttons:
button.led_on()
time.sleep(0.1)
button.led_off()
# Neopixels fill all
for color in leds.COLORS.values():
leds.fill_all(color)
leds.show_pixels()
time.sleep(0.2)
# Neopixels fill by group
for _ in range(10):
for led_group in leds.led_groups.values():
led_group.fill(random.choice(list(leds.COLORS.values())))
leds.show_pixels()
time.sleep(0.2)
# Neopixels chase by group
for led_group in leds.led_groups.values():
random_color = random.choice(list(leds.COLORS.values()))
for color in [random_color, leds.COLORS['black']]:
for i in range(led_group.num_leds):
led_group.pixels[i].value = color
leds.show_pixels()
if __name__ == '__main__':
# TODO: Try using a timer for leds.show_pixels(). Will it fix the glitch?
buttons = [Button(*pin_nums, Button.led_on, Button.led_off)
for pin_nums in BUTTON_PIN_NUMS]
leds = Leds(LED_GROUPS, BRIGHTNESS, PIN_NUM)
demo(buttons, leds)