-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.py
58 lines (52 loc) · 1.75 KB
/
code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import time
import board
import digitalio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
keyboard = Keyboard(usb_hid.devices)
debug = False
sleep_time = 0.01
timer_sec = time.monotonic()
# Liste der Tasten und ihre zugehörigen Pins und Keycodes
buttons = [
{"pin": board.GP15, "keycode": Keycode.V, "state": False},
{"pin": board.GP17, "keycode": Keycode.B, "state": False},
{"pin": board.GP14, "keycode": Keycode.N, "state": False},
{"pin": board.GP16, "keycode": Keycode.M, "state": False},
{"pin": board.GP18, "keycode": Keycode.C, "state": False},
]
# Initialisierung der Tasten
for button in buttons:
button["pin"] = digitalio.DigitalInOut(button["pin"])
button["pin"].direction = digitalio.Direction.INPUT
button["pin"].pull = digitalio.Pull.UP
def timeout():
global timer_sec
if (time.monotonic() - timer_sec) > 90:
keyboard.release_all()
keyboard.press(Keycode.ENTER)
time.sleep(0.05)
keyboard.release_all()
time.sleep(1)
keyboard.press(Keycode.ENTER)
time.sleep(0.05)
keyboard.release_all()
time.sleep(1)
timer_sec = time.monotonic()
while True:
for button in buttons:
if not(button["pin"].value) and not(button["state"]):
timeout()
button["state"] = True
keyboard.press(button["keycode"])
if debug:
print(f'{button["keycode"]} an')
time.sleep(sleep_time)
if (button["pin"].value) and (button["state"]):
timeout()
button["state"] = False
keyboard.release(button["keycode"])
if debug:
print(f'{button["keycode"]} aus')
time.sleep(sleep_time)