Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Trying to loop an led_animation (x)times
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Trying to loop an led_animation (x)times

by B3nimbl3 on Thu Oct 21, 2021 3:07 pm

My chime function fails to complete a cycle.

Code: Select all | TOGGLE FULL SIZE
rainbow_comet_v = RainbowComet(pixel_cob_vertical, speed=0.1, tail_length=15, bounce=False)

def chime():
    global Chime
    if Chime > 0:
        animation = (rainbow_comet_v)
        animation.animate()
        Chime -= 1



I am Here https://circuitpython.readthedocs.io/pr ... t/api.html
Above example stops after "Chime" number of steps into animation and I can't seem to figure out
how to only decrement counter after cycle complete.

B3nimbl3
 
Posts: 4
Joined: Tue Dec 29, 2020 7:45 pm

Re: Trying to loop an led_animation (x)times

by B3nimbl3 on Fri Oct 22, 2021 11:51 am

I'll try to figure out a better way to ask

B3nimbl3
 
Posts: 4
Joined: Tue Dec 29, 2020 7:45 pm

Re: Trying to loop an led_animation (x)times

by tannewt on Mon Oct 25, 2021 3:54 pm

Here is my guess (untested!) to how it should work:

Code: Select all | TOGGLE FULL SIZE
animation = RainbowComet(pixel_cob_vertical, speed=0.1, tail_length=15, bounce=False)

def chime():
    print("chime")
    if animation.cycle_count > 3:
        animation.stop()

animation.add_cycle_complete_receiver(chime)
animation.animate()
print("done")



The `chime` function should be called on every cycle complete by the code in animate(). Animations appear to track how many cycles they've completed so I've used that instead of a separate counter.

tannewt
 
Posts: 2683
Joined: Thu Oct 06, 2016 8:48 pm

Re: Trying to loop an led_animation (x)times

by B3nimbl3 on Thu Nov 04, 2021 10:07 am

Thank you so much! That's just what I needed!

B3nimbl3
 
Posts: 4
Joined: Tue Dec 29, 2020 7:45 pm

Please be positive and constructive with your questions and comments.