#Seesaw 1x4 neokey asyncio

1 messages · Page 1 of 1 (latest)

stray hatch
#

I'm having rouble getting an async "monitor button" function to work with a neokey 1x4. I'm trying to adapt the example code, but I am either getting a "not implemented", or "AttributeError: 'tuple' object has no attribute 'try_lock'" error. This is a basic version of my code that is pulling the "try_lock" error. Any help please!

#
import board
import asyncio
from adafruit_neokey.neokey1x4 import NeoKey1x4
from adafruit_seesaw import keypad
i2c_bus = board.I2C()
import displayio
neokey = NeoKey1x4(i2c_bus, addr=0x30)

class Controls:
    """The controls to allow you to vary the rainbow and blink animations."""
    def __init__(self):
        self.reverse = False
        self.wait = 0.01

        
async def monitor_button(on_off_pin, faster_pin, slower_pin):
    with keypad.Keypad(
        (on_off_pin, faster_pin, slower_pin) #value_when_pressed=False, pull=True
    ) as keys:
        while True:
            key_event = keys.events.get()
            if key_event and key_event.pressed:
                key_number = key_event.key_number
                print("BUTTON {} PRESSED!".format(key_number))
                if key_number == 0:
                    print("It is Key_Number 0!, reverse_pin")
                    controls.reverse = not controls.reverse
                if key_number == 1:
                    print("It is key_Number 1!, faster_pin")
                    controls.wait = controls.wait + 0.01
                if key_number == 2:
                    print("It is Key_Number 2!, slower_pin")
                    controls.wait = controls.wait - 0.01
            await asyncio.sleep(0)
            
async def main():
    button_task = asyncio.create_task(monitor_button(neokey[0], neokey[1], neokey[2]))
    await asyncio.gather(button_task)

asyncio.run(main()) ```
formal coyote