@pythoncoder I read/looked at the document link you posted and I am lost on how to get this working. All I wanted to do was when the button was pressed just run the function twice. Can you give me an example with my code please?
I did find a video by Digi-Key based off your Asyncio
HERE. I got it working with his video BUT im not running multiple things at one time, I just wanted to loop the display 2x.
Thanks,
Code: Select all
# Coroutine: blink on a timer
async def blink(delay):
while True:
led.toggle()
await uasyncio.sleep(delay)
# Coroutine: only return on button press
async def wait_button():
btn_prev = btn_show_display.value()
while (btn_show_display.value() == 1) or (btn_show_display.value() == btn_prev):
btn_prev = btn_show_display.value()
await uasyncio.sleep(0.04)
# Coroutine: entry point for asyncio program
async def main():
# Start coroutine as a task and immediately return
uasyncio.create_task(blink(0.2))
while True:
# Calculate time between button presses
await wait_button()
for i in range(2):
# Scroll in, stop, scroll out (vertical)
scroll_in_screen_v(OLED_screen1)
time.sleep(5) # Sleep for 5 seconds
scroll_out_screen_v(2)
scroll_in_screen_v(OLED_screen2)
time.sleep(5) # Sleep for 5 seconds
scroll_out_screen_v(2)
# Start event loop and run entry point coroutine
uasyncio.run(main())