-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
executable file
·79 lines (64 loc) · 1.86 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import time
import board
import digitalio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
from adafruit_debouncer import Debouncer
# Set your pins here
btn_A_pin = board.GP16
btn_B_pin = board.GP17
btn_X_pin = board.GP18
btn_Y_pin = board.GP19
# Set your keys here
btn_A_key = Keycode.Q
btn_B_key = Keycode.W
btn_X_key = Keycode.E
btn_Y_key = Keycode.R
# Set up HID keyboard
keyboard = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(keyboard)
# Set up pins
btn_A = digitalio.DigitalInOut(btn_A_pin)
btn_A.direction = digitalio.Direction.INPUT
btn_A.pull = digitalio.Pull.DOWN
btn_A_switch = Debouncer(btn_A)
btn_B = digitalio.DigitalInOut(btn_B_pin)
btn_B.direction = digitalio.Direction.INPUT
btn_B.pull = digitalio.Pull.DOWN
btn_B_switch = Debouncer(btn_B)
btn_X = digitalio.DigitalInOut(btn_X_pin)
btn_X.direction = digitalio.Direction.INPUT
btn_X.pull = digitalio.Pull.DOWN
btn_X_switch = Debouncer(btn_X)
btn_Y = digitalio.DigitalInOut(btn_Y_pin)
btn_Y.direction = digitalio.Direction.INPUT
btn_Y.pull = digitalio.Pull.DOWN
btn_Y_switch = Debouncer(btn_Y)
# Main loop
while True:
btn_A_switch.update()
btn_B_switch.update()
btn_X_switch.update()
btn_Y_switch.update()
# A Button: letter Q
if btn_A_switch.rose:
keyboard.press(btn_A_key)
if btn_A_switch.fell:
keyboard.release(btn_A_key)
# B Button: letter W
if btn_B_switch.rose:
keyboard.press(btn_B_key)
if btn_B_switch.fell:
keyboard.release(btn_B_key)
# X Button: letter E
if btn_X_switch.rose:
keyboard.press(btn_X_key)
if btn_X_switch.fell:
keyboard.release(btn_X_key)
# Y Button: letter R
if btn_Y_switch.rose:
keyboard.press(btn_Y_key)
if btn_Y_switch.fell:
keyboard.release(btn_Y_key)