36 lines
497 B
Python
36 lines
497 B
Python
|
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)
|