From 9e4e14e8acc1f855525430c990c439e3a6d228d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Rasmussen?= Date: Mon, 1 Aug 2022 15:38:31 +0200 Subject: [PATCH] Initial commit --- main.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..ab48bac --- /dev/null +++ b/main.py @@ -0,0 +1,35 @@ +import machine +import pyb + +KEY_KEYPAD_PLUS = 0x57 + +hid = pyb.USB_HID() +button = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_UP) + +def press_key_once(key1): + buf = bytearray(8) + buf[2] = key1 + hid.send(buf) + pyb.delay(10) + +def release_key_once(): + press_key_once(0) + + +buf = bytearray(8) + +state = False +while True: + pressed = not bool(button.value()) + + if pressed == state: + continue + + if pressed: + press_key_once(KEY_KEYPAD_PLUS) + else: + release_key_once() + + state = pressed + + pyb.delay(10)