|
1 |
| -# SPDX-FileCopyrightText: 2021 Noe Ruiz for Adafruit Industries |
| 1 | +# SPDX-FileCopyrightText: 2021 Liz Clark for Adafruit Industries |
2 | 2 | # SPDX-License-Identifier: MIT
|
3 | 3 |
|
4 |
| -""" |
5 |
| -NeoPixel Menorah using QT Py RP2040. |
6 |
| -""" |
| 4 | +import time |
7 | 5 | import board
|
8 | 6 | 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 |
13 | 9 | from adafruit_led_animation.sequence import AnimationSequence
|
| 10 | +from adafruit_led_animation import helper |
14 | 11 | from adafruit_led_animation.color import AMBER
|
15 | 12 |
|
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 |
17 | 19 | pixel_pin = board.D0
|
18 |
| -# Update to match the number of NeoPixels you have connected |
19 | 20 | pixel_num = 9
|
20 | 21 |
|
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) |
22 | 23 |
|
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 |
27 | 26 |
|
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) |
35 | 32 | )
|
36 | 33 |
|
| 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 | + |
37 | 43 | 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 |
38 | 53 | 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