microbit-foundation / micropython-microbit-v2

Temporary home for MicroPython for micro:bit v2 as we stablise it before pushing upstream
MIT License
41 stars 22 forks source link

Update `power.deep_sleep()` with CODAL non-blocking `uBit.power.deepSleep()` #119

Closed microbit-carlos closed 1 year ago

microbit-carlos commented 1 year ago

Looks like it will be an extra argument with a flag:

The CODAL next tag hasn't been release yet, so for the moment this is a placeholder issue for when it can be integrated.

microbit-carlos commented 1 year ago

Not 100% sure if it's the same issue, but a programme without the ms argument and with button A and run_every as wake sources, and it looks like power.deep_sleep() also blocks until the run_every function runs.

So, with this programme, when I press button A soon after the board has woken up (it shows the surprised face), it will wake up, show the surprise face, and stay there until the next time run_every is fired (which can be tracked via serial print()), only then it will finally scroll "text".

from microbit import *
import power

@run_every(s=10)
def log_temperature():
    print(running_time())

display.show(Image.SURPRISED)
while True:
    if button_a.was_pressed():
        display.scroll("text")
        display.show(Image.SURPRISED)
    power.deep_sleep(wake_on=button_a, run_every=True)
microbit-carlos commented 1 year ago

This has been updated in PR: