Hi, I spent a few hours reading and studying the async tutorial; it was very interesting. Even though MicroPython is a subset of Python, it seems very capable, with many features that I won't use (famous last words?).
So I modified the test program to work with my board, but I could not get it to register the button press. I think this might be because I am using an ESP32, whereas the code is written for a Pyboard. I have put my test code below and I'm hoping somebody might be able to spot the problem. I'm using pin 25 as an input, pulling it from low to high (not grounding it to pull low).
I'm wondering if I should be seeing the REPL prompt when I run it?
I'm calling it at the end of the script with this:
test_btn(suppress=False, lf=True, df=True)
and it looks like this in terminal:
>>>import s
Test of pushbutton scheduling coroutines.
Test using switch or pushbutton between X1 and gnd.
Ground pin X2 to terminate test.
Soft reset (ctrl-D) after each test.
Doubleclick enabled
Long press enabled
>>> ???
Regards, AB
Code: Select all
# START MODIFIED BUTTON TEST
#==================================
# print to REPL (coroutine)
async def print_repl(action, delay):
if action == 'pressed': print('\n---\nbutton was pressed')
if action == 'released': print('button was released')
if action == 'double-click': print('double click was registered')
if action == 'long-press': print('long press was registered')
await asyncio.sleep_ms(delay)
print ('pause timer done\n---\n')
# Quit test by connecting 26 to ground
async def killer_switch():
pin = Pin(26, Pin.IN, Pin.PULL_DOWN)
while pin.value() == 0:
await asyncio.sleep_ms(50)
# Test for the Pushbutton class (coroutines)
# Pass True to test suppress
def test_btn(suppress=False, lf=True, df=True):
print('Test of pushbutton scheduling coroutines.')
pin = Pin(25, Pin.IN, Pin.PULL_DOWN)
pb = Pushbutton(pin, suppress)
pb.press_func(print_repl, ('pressed', 1000))
pb.release_func(print_repl, ('released', 1000))
if df:
print('Doubleclick enabled')
pb.double_func(print_repl, ('double-click', 1000))
if lf:
print('Long press enabled')
pb.long_func(print_repl, ('long-press', 1000))
loop = asyncio.get_event_loop()
loop.run_until_complete(killer_switch())
# END MODIFIED TEST
# ======================================