Last active
October 30, 2022 20:55
-
-
Save andywarburton/81ee4d4944e7c8a1a6613ac0325e514d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Example for Pico. Blinks the built-in LED.""" | |
import board | |
import digitalio | |
import os | |
import neopixel | |
from digitalio import DigitalInOut, Direction, Pull | |
from adafruit_debouncer import Debouncer | |
from adafruit_led_animation.animation.rainbow import Rainbow | |
from adafruit_led_animation.animation.rainbowchase import RainbowChase | |
from adafruit_led_animation.animation.rainbowcomet import RainbowComet | |
from adafruit_led_animation.animation.rainbowsparkle import RainbowSparkle | |
from adafruit_led_animation.animation.SparklePulse import SparklePulse | |
from adafruit_led_animation.color import ORANGE, BLACK | |
button_pin = board.D9 | |
rgb_pin = board.D7 | |
# neopixels | |
num_pixels = 24 | |
pixels = neopixel.NeoPixel(rgb_pin, num_pixels) | |
pixels.brightness = 0.3 | |
# set up the button and enable debouncing | |
btn = digitalio.DigitalInOut(button_pin) | |
btn.direction = digitalio.Direction.INPUT | |
btn.pull = digitalio.Pull.UP | |
button = Debouncer(btn, interval=0.1) | |
prev_state = button.value | |
# animations | |
rainbow = Rainbow(pixels, speed=0.1, period=5) | |
rainbow_chase = RainbowChase(pixels, speed=0.1, size=6, spacing=6) | |
rainbow_comet = RainbowComet(pixels, speed=0.1, tail_length=8, bounce=False) | |
rainbow_sparkle = RainbowSparkle(pixels, speed=0.05, num_sparkles=8) | |
fire = SparklePulse(pixels, speed=0.1, period=5, color=ORANGE) | |
mode = 0 | |
pixels.fill((0, 0, 0)) | |
while True: | |
button.update() | |
# button pressed | |
if button.fell: | |
if(mode < 3): | |
mode = mode+1 | |
else: | |
mode = 0 | |
print("Mode:", mode) | |
if(mode == 0): | |
fire.animate() | |
elif(mode == 1): | |
rainbow_chase.animate() | |
elif(mode == 2): | |
rainbow_comet.animate() | |
else: | |
rainbow.animate() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment