Trying to loop an led_animation (x)times

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
B3nimbl3
 
Posts: 4
Joined: Tue Dec 29, 2020 7:45 pm

Trying to loop an led_animation (x)times

Post by B3nimbl3 »

My chime function fails to complete a cycle.

Code: Select all

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.

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

Re: Trying to loop an led_animation (x)times

Post by B3nimbl3 »

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

User avatar
tannewt
 
Posts: 3305
Joined: Thu Oct 06, 2016 8:48 pm

Re: Trying to loop an led_animation (x)times

Post by tannewt »

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

Code: Select all

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.

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

Re: Trying to loop an led_animation (x)times

Post by B3nimbl3 »

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

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

Return to “Adafruit CircuitPython”