slow animations

This is a special forum devoted to educators using Adafruit and Arduino products for teaching.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Quaddam
 
Posts: 52
Joined: Fri Nov 11, 2016 1:49 pm

slow animations

Post by Quaddam »

Hi one of my students created this code below but it seems to run extremely slow (the animations are not moving at the correct speed) just wondering where she could make some changes?

Code: Select all

import board
from neopixel import NeoPixel
from analogio import AnalogIn
from adafruit_led_animation.animation.chase import Chase
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.color import WHITE, PURPLE
import time


pixels = NeoPixel(board.D1, 60, brightness=1, auto_write=True)
pot = AnalogIn(board.A2)
chase = Chase(pixels, speed=0.1, color=WHITE, size=3, spacing=6)
comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)

def show_colours(val):
    if(val > 0 and val < 5):
            comet.animate()
    elif(val >= 5 and val <= 10):
        chase.animate()
    
chase = Chase(pixels, speed=0.1, color=WHITE, size=3, spacing=6)
comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)

while True:
    show_colours(int(pot.value/65520*10))
    time.sleep(0.25)
    print((pot.value))

User avatar
rpiloverbd
 
Posts: 198
Joined: Mon Nov 29, 2021 8:13 am

Re: slow animations

Post by rpiloverbd »

Does she see any change if she changes the speed in line#10 and line#11?

User avatar
Quaddam
 
Posts: 52
Joined: Fri Nov 11, 2016 1:49 pm

Re: slow animations

Post by Quaddam »

We figured it out, thanks for the repsonse, wondering though with the code below, how we could keep the animation playing? the animation moves one step each time we press the button, if we put in a whileTrue loop at line 22 it just stays stuck on that animation? is there a way to break out of while True: loops?

Code: Select all

import board
from neopixel import NeoPixel
from adafruit_debouncer import Debouncer
from adafruit_led_animation.animation.chase import Chase
from adafruit_led_animation.color import PURPLE, ORANGE
from digitalio import DigitalInOut, Direction, Pull

pixels = NeoPixel(board.D1, 60, brightness=1, auto_write=True)
chase = Chase(pixels, speed=0.1, color=PURPLE, size=3, spacing=6)
change = False
        
button = DigitalInOut(board.D2)
button.direction = Direction.INPUT
button.pull = Pull.UP
toggle = Debouncer(button)

chase = Chase(pixels, speed=0.01, color=PURPLE, size=3, spacing=6)
chase1 = Chase(pixels, speed=0.01, color=ORANGE, size=3, spacing=6)

def change_animation(state):
    if(state == 1):
        chase.animate()
    else:
        chase1.animate()

while True:
    toggle.update()
    if toggle.fell:
        change = not change
        change_animation(change)

User avatar
sipan1313
 
Posts: 18
Joined: Sun Jan 30, 2022 4:37 pm

Re: slow animations

Post by sipan1313 »

hello

you can read this: viewtopic.php?f=25&p=685178

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

Return to “For Educators”