Keypad input-type compatability

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Daft_vagabond
 
Posts: 92
Joined: Thu May 28, 2020 2:53 pm

Keypad input-type compatability

Post by Daft_vagabond »

For a bit of context: I'm trying to learn how best to use asyncio. In the asyncio guide, it suggests to handle input interrupts with the keypad lib. I know the keypad lib accommodates using any number of pins so that one can customize the inputs being detected by keypad.

I'm curious, is there a way I could use touchio to set up a touch input and pass that through keypad as a key?

To use the "Handling Interrupts with keypad" guide as a reference, could I do something like this?

Code: Select all

import asyncio
import board
import keypad

touch_A1 = touchio.TouchIn(board.A1) # Set up the touch input

async def catch_pin_transitions(pin):
    """Print a message when pin goes low and when it goes high."""
    with keypad.Keys((pin,), value_when_pressed=False) as keys:
        while True:
            event = keys.events.get()
            if event:
                if event.pressed:
                    print("pin went low")
                elif event.released:
                    print("pin went high")
            await asyncio.sleep(0)

async def main():
    interrupt_task = asyncio.create_task(catch_pin_transitions(touch_A1)) # pass that pin as in input for kaypad, or maybe it could remain as board.A1
    await asyncio.gather(interrupt_task)

asyncio.run(main())

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”