adafruit / Adafruit_CircuitPython_asyncio

CIrcuitPython subset of CPython asyncio library
MIT License
28 stars 16 forks source link

adding display button example #21

Closed FoamyGuy closed 2 years ago

FoamyGuy commented 2 years ago

adds a new example that illustrates the usage of Display_Button with asyncio using some blinking vectorio.Circle objects instead of blinking LEDs and physical momentary switches.

kmatch98 commented 2 years ago

I tested on the PyPortal and found one weirdness that I can't explain. If I keep pressing the "invert colors" button a lot, pretty fast. Eventually the green button disappears and never returns. I suspect that it's going transparent and somehow not retriggering a "make_opaque". But an initial look in the code didn't turn up a clear answer.

It's a minor issue but was strange.

aioue commented 2 years ago

Eventually the green button disappears and never returns.

If you don't touch anything it will eventually disappear after about 15 seconds.

Recorded screen: https://youtu.be/5gCUo6tLKzg

FoamyGuy commented 2 years ago

Thanks for the testing and feedback everyone! Much appreciated!

@aioue Thanks for recording this and sharing the video. and @kmatch98 if this is the same issue you noticed.

In this case the green circle intentionally disappears after a while. On line 308 in the example:

blink(palette_2, interval_2, 20, color_btn_state)

The 3rd argument indicates the number of times to run the blink action. This is set to 20, so the green circle blinks 20 times and then disappears and isn't shown again. I included this one to show an example of tasks that operate a certain number of times and then conclude.

This code was originall inpspired by the LED examples in the cooperative multi-tasking guide: https://learn.adafruit.com/cooperative-multitasking-in-circuitpython-with-asyncio/concurrent-tasks#two-leds-3106214-5 which are coded with a very similar count argument that controls how many times the blink should occur.

The blue circle uses -1 for the count which is a special value that makes it infiite / loop forever so it will continue blinking forever without stopping after a certain count:

blink(palette_1, interval_1, -1, color_btn_state)
aioue commented 2 years ago

LGTM, keen to see this get merged and improved on - the other PyPortal UI guide doesn't use async and is somewhat laggy 😄