-
Notifications
You must be signed in to change notification settings - Fork 768
/
code.py
executable file
·72 lines (60 loc) · 2.12 KB
/
code.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
# SPDX-FileCopyrightText: 2021 Liz Clark for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import board
import neopixel
from digitalio import DigitalInOut, Direction, Pull
from adafruit_led_animation.animation.rainbow import Rainbow
from adafruit_led_animation.sequence import AnimationSequence
from adafruit_led_animation import helper
from adafruit_led_animation.color import AMBER
# button setup
button = DigitalInOut(board.D1)
button.direction = Direction.INPUT
button.pull = Pull.UP
# neopixel setup
pixel_pin = board.D0
pixel_num = 9
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.3, auto_write=False)
# variable for number of pixels in the pixelmap helper
num = 1
# pixel map helper
# allows you to light each candle up one by one
# begins with one being lit (num)
candles = helper.PixelMap.horizontal_lines(
pixels, num, 1, helper.horizontal_strip_gridmap(pixel_num, alternating=False)
)
# rainbow animation
rainbow = Rainbow(candles, speed=0.1, period=5)
animations = AnimationSequence(rainbow)
# turn on center candle
pixels[4] = AMBER
pixels.show()
while True:
# if only one candle is lit, don't rewrite center neopixel
if num == 1:
pass
# otherwise write data to center neopixel
else:
pixels[4] = AMBER
pixels.show()
# animation the rainbow animation
animations.animate()
# if you press the button...
if not button.value:
# if all of the candles are not lit up yet...
if num < 9:
# increase value of num by one
num += 1
# skip the center candle so that it stays amber
if num == 4:
num = 5
# recreate the pixel helper to increase the size of the horizontal grid
# this is how the next neopixel is lit up in the sequence
candles = helper.PixelMap.horizontal_lines(
pixels, num, 1, helper.horizontal_strip_gridmap(pixel_num, alternating=False)
)
rainbow = Rainbow(candles, speed=0.1, period=5)
animations = AnimationSequence(rainbow)
# quick delay so that everything flows well
time.sleep(0.5)