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()
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