"rainbow.period = VARIABLE" not working?

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
RGB_Dude
 
Posts: 12
Joined: Wed Dec 29, 2021 1:23 pm

"rainbow.period = VARIABLE" not working?

Post by RGB_Dude »

Code: Select all

import neopixel
import board
import digitalio
import time
from adafruit_led_animation.animation.rainbow import Rainbow

numpix = 32
pixels = neopixel.NeoPixel(board.GP5, numpix, brightness=1, auto_write=True)
pixels.fill(0)
pixels.show()
time.sleep(0.01)

presses = 1
SPEED = 1

button = digitalio.DigitalInOut(board.GP6)
button.switch_to_input(pull=digitalio.Pull.UP)

rainbow = Rainbow(pixels, speed=0, period=SPEED, step=2.4, precompute_rainbow=True)

while True:
        if not button.value:
            presses = presses + 1
            if presses > 10:
                SPEED = 1
                presses = 1
                print("Speed reset:", SPEED, presses)
            elif presses < 11:
                SPEED = SPEED + 5
                print("Speed decreased:", SPEED, presses)
            time.sleep(0.2)
        rainbow.period = SPEED
        rainbow.animate()
Why is this not working? The rainbow animation works fine of course, but the speed (the period variable) only affects the animation speed if changed manually at the beginning when defining the animation. Later in the code it seemingly cannot be changed or at least nothing happens. The code still runs fine.

Am I doing something wrong? "rainbow.speed = VARIABLE" does work by the way, but it doesn't affect the animation speed in a strict sense of the word. Is there anything to update the rainbow.period during "while true"?

PS.

rainbow.generate_rainbow()
rainbow.reset()

these also don't seem to have any effect

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”