File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: 2021 john park for Adafruit Industries
2+ # SPDX-License-Identifier: MIT
3+ # Pico Four Key USB HID Keypad
4+
5+ import board
6+ from digitalio import DigitalInOut , Pull
7+ from adafruit_debouncer import Debouncer
8+ import usb_hid
9+ from adafruit_hid .keyboard import Keyboard
10+ from adafruit_hid .keycode import Keycode
11+
12+ kpd = Keyboard (usb_hid .devices )
13+
14+ # define buttons
15+ num_keys = 4
16+ pins = (
17+ board .GP0 ,
18+ board .GP1 ,
19+ board .GP2 ,
20+ board .GP3
21+ )
22+
23+ keys = []
24+ for pin in pins :
25+ tmp_pin = DigitalInOut (pin )
26+ tmp_pin .pull = Pull .UP
27+ keys .append (Debouncer (tmp_pin ))
28+
29+ keymap = {
30+ (0 ): ("Select all" , [Keycode .GUI , Keycode .A ]),
31+ (1 ): ("Cut" , [Keycode .GUI , Keycode .X ]),
32+ (2 ): ("Copy" , [Keycode .GUI , Keycode .C ]),
33+ (3 ): ("Paste" , [Keycode .GUI , Keycode .V ])
34+ }
35+
36+ print ("\n Welcome to keypad" )
37+ print ("keymap:" )
38+ for k in range (num_keys ):
39+ print ("\t " , (keymap [k ][0 ]))
40+
41+
42+ while True :
43+ for i in range (num_keys ):
44+ keys [i ].update ()
45+ if keys [i ].fell :
46+ print (keymap [i ][0 ])
47+ kpd .send (* keymap [i ][1 ])
You can’t perform that action at this time.
0 commit comments