Skip to content

Commit c1a45d4

Browse files
authored
Merge pull request #1928 from adafruit/neoPixelMenorah
Adding code for NeoPixel Menorah
2 parents 96a5bc8 + 7fa4a07 commit c1a45d4

File tree

1 file changed

+56
-22
lines changed

1 file changed

+56
-22
lines changed

NeoPixel_Menorah/code.py

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,72 @@
1-
# SPDX-FileCopyrightText: 2021 Noe Ruiz for Adafruit Industries
1+
# SPDX-FileCopyrightText: 2021 Liz Clark for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33

4-
"""
5-
NeoPixel Menorah using QT Py RP2040.
6-
"""
4+
import time
75
import board
86
import neopixel
9-
from adafruit_led_animation.animation.pulse import Pulse
10-
from adafruit_led_animation.animation.solid import Solid
11-
from adafruit_led_animation.animation.sparkle import Sparkle
12-
from adafruit_led_animation.animation.chase import Chase
7+
from digitalio import DigitalInOut, Direction, Pull
8+
from adafruit_led_animation.animation.rainbow import Rainbow
139
from adafruit_led_animation.sequence import AnimationSequence
10+
from adafruit_led_animation import helper
1411
from adafruit_led_animation.color import AMBER
1512

16-
# Update to match the pin connected to your NeoPixels
13+
# button setup
14+
button = DigitalInOut(board.D1)
15+
button.direction = Direction.INPUT
16+
button.pull = Pull.UP
17+
18+
# neopixel setup
1719
pixel_pin = board.D0
18-
# Update to match the number of NeoPixels you have connected
1920
pixel_num = 9
2021

21-
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=1, auto_write=False)
22+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.3, auto_write=False)
2223

23-
solid = Solid(pixels, color=AMBER)
24-
pulse = Pulse(pixels, speed=0.05, color=AMBER, period=5)
25-
sparkle = Sparkle(pixels, speed=0.15, color=AMBER, num_sparkles=10)
26-
chase = Chase(pixels, speed=0.1, color=AMBER, size=1, spacing=8)
24+
# variable for number of pixels in the pixelmap helper
25+
num = 1
2726

28-
animations = AnimationSequence(
29-
chase,
30-
pulse,
31-
sparkle,
32-
solid,
33-
advance_interval=5,
34-
auto_clear=True,
27+
# pixel map helper
28+
# allows you to light each candle up one by one
29+
# begins with one being lit (num)
30+
candles = helper.PixelMap.horizontal_lines(
31+
pixels, num, 1, helper.horizontal_strip_gridmap(pixel_num, alternating=False)
3532
)
3633

34+
# rainbow animation
35+
rainbow = Rainbow(candles, speed=0.1, period=5)
36+
37+
animations = AnimationSequence(rainbow)
38+
39+
# turn on center candle
40+
pixels[4] = AMBER
41+
pixels.show()
42+
3743
while True:
44+
45+
# if only one candle is lit, don't rewrite center neopixel
46+
if num == 1:
47+
pass
48+
# otherwise write data to center neopixel
49+
else:
50+
pixels[4] = AMBER
51+
pixels.show()
52+
# animation the rainbow animation
3853
animations.animate()
54+
55+
# if you press the button...
56+
if not button.value:
57+
# if all of the candles are not lit up yet...
58+
if num < 9:
59+
# increase value of num by one
60+
num += 1
61+
# skip the center candle so that it stays amber
62+
if num == 4:
63+
num = 5
64+
# recreate the pixel helper to increase the size of the horizontal grid
65+
# this is how the next neopixel is lit up in the sequence
66+
candles = helper.PixelMap.horizontal_lines(
67+
pixels, num, 1, helper.horizontal_strip_gridmap(pixel_num, alternating=False)
68+
)
69+
rainbow = Rainbow(candles, speed=0.1, period=5)
70+
animations = AnimationSequence(rainbow)
71+
# quick delay so that everything flows well
72+
time.sleep(0.5)

0 commit comments

Comments
 (0)