#Blink Animation - Debounced button

1 messages · Page 1 of 1 (latest)

idle dove
#

import board
import neopixel
import digitalio
import time 
from adafruit_led_animation.sequence import AnimationSequence
import adafruit_led_animation.animation.blink as blink_animation
import adafruit_led_animation.color as color
from adafruit_debouncer import Button

pixels = neopixel.NeoPixel(board.D12, 30, brightness=0.05)
blink = blink_animation.Blink(pixels, 0.5, color.RED)

animations = False

button_input = digitalio.DigitalInOut(board.D9)
button_input.switch_to_input(pull=digitalio.Pull.UP)
button = Button(button_input)

while True:
    button.update()
    if button.pressed:
        print("button pressed")
        if animations:
            animations = False
            print("animations turned OFF")
            pixels.fill(color.GREEN)
            pixels.show()
           
        else:
            animations = True
            print("Animations turned ON")
            blink.animate()

If I turn the microcontroller on, at first the lights are black/off. 
By pushing the button it turns GREEN but it is not blinking. Pushing again the leds turn RED. Pushing again it is black/off. Then red - green - red - off - red - green - red - off and so on.

CircuitPython REPL
button pressed
Animations turned ON
button pressed
animations turned OFF
button pressed
Animations turned ON
button pressed
animations turned OFF
button pressed
Animations turned ON

Where is the issue? It does not blink and remains in one color as long as the button is pressed again. Any ideas? Thank you in advance!

neat solar
#

Hi! You'll want to ask this in #help-with-circuitpython - this channel is for when Adafruit has a live show and people probably won't see your post here to get you help. Also see #welcome for how to format code when you paste it.

idle dove