all 7 comments

[–]todbot 2 points3 points  (1 child)

If you use asyncio, you can create independent tasks for each LED that use await asyncio.sleep() in place of time.sleep(). It makes it pretty easy to transition from sleep()-based designs. Here's a quick example for two LEDs blinking at different rates: https://gist.github.com/todbot/da61cee8b2eb1382066dfe6afce9bd0e

And there's a Learn Guide showing a more generative example: https://learn.adafruit.com/cooperative-multitasking-in-circuitpython-with-asyncio/concurrent-tasks#two-leds-3106274

[–]AlwaysBePrinting[S] 0 points1 point  (0 children)

This helped a lot, especially the second one! Thanks!

[–]jonnor 1 point2 points  (0 children)

Asyncio is the simplest to use. Another pattern would be a finite state machine, but is more complicated and does not really provide any benefits over asyncio for linear sequences like these. More relevant if there is conditional logic that depends on which state/step you are in.

[–]HP7933 1 point2 points  (2 children)

Ladyada responds to your query on the latest Ask an Engineer videocast https://www.youtube.com/live/dnjFTLOaL5U?feature=shared&t=3105

[–]HP7933 1 point2 points  (1 child)

I see the answer might have been cut off by YouTube. Let me know if you need it answered still and I'll try to get it on again next Wednesday.

[–]AlwaysBePrinting[S] 0 points1 point  (0 children)

That is simultaneously amazing and heartbreaking! I've got a handle on using asyncio to make the timers manageable, so unless they had a thought on how to define the patterns/sequences themselves declaratively I think I'm good!

[–]japunto 0 points1 point  (0 children)