I found machine.lightsleep() to do what I want but it looks like I can't tell it to wait for more than one Pin to go LOW with `esp32.wake_on_ext0()` or `esp32.wake_on_ext1()` - since you can only specify WAKEUP_ALL_LOW or WAKEUP_ANY_HIGH.
What I need is a way to say "lightsleep() until any of given GPIOs change" or at least ".. until any of them goes LOW" but there is no `esp32.WAKEUP_ANY_LOW`.
is `esp32.wake_on_ext0/1()` the right thing to use here anyway?
Here is, what I got:
Code: Select all
import esp32
from machine import lightsleep, Pin
from utime import sleep_ms
btn1_pin = Pin(36, Pin.IN)
btn2_pin = Pin(13, Pin.IN)
esp32.wake_on_ext0(pin=btn1_pin, level=esp32.WAKEUP_ALL_LOW)
# a second call makes the first one not work any more
#esp32.wake_on_ext0(pin=btn2_pin, level=esp32.WAKEUP_ALL_LOW)
#esp32.wake_on_ext0(pin=btn2_pin, level=esp32.WAKEUP_ALL_LOW)
#esp32.wake_on_ext1(pins=(device.pin_bA, device.pin_bB), level=esp32.WAKEUP_ALL_LOW)
print("Press buttons 1 or 2")
sleep_ms(5)
while True:
lightsleep(2000) # wait for button presses - works for one button only
if btn1_pin.value() == 0:
print("Button1 pressed")
while btn1_pin.value() == 0:
# I'd like to use lightsleep here, too, but I don't know how
sleep_ms(5)
print("Button1 released")
# this won't be reached if I don't press Button1, too
if btn2_pin.value() == 0:
print("Button2 pressed")
while btn2_pin.value() == 0:
# I'd like to use lightsleep here, too, but I don't know how
sleep_ms(5)
print("Button2 released")