A simple script that turns a pin into a keypress
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

43 lines
946 B

from adafruit_hid.keycode import Keycode
from adafruit_hid.keyboard import Keyboard
from adafruit_debouncer import Debouncer
import usb_hid
import digitalio
import board
############# WIRING #############
#
# GND <-> Audio Jack Ground
# GP1 <-> Audio Jack Left/Right
#
########### END WIRING ###########
############# CONFIG #############
keycodePress = Keycode.D
readPin = board.GP5
########### END CONFIG ###########
######## SYSTEM VARIABLES ########
# Keyboard
kbd = Keyboard(usb_hid.devices)
# Button/Switch
pin = digitalio.DigitalInOut(readPin)
pin.direction = digitalio.Direction.INPUT
pin.pull = digitalio.Pull.UP
switch = Debouncer(pin, interval=0.02)
###### END SYSTEM VARIABLES ######
### BEGIN PROGRAM ###
# Clean up any left over keypresses, sometimes they happen
kbd.release_all()
while True:
switch.update()
if switch.rose:
kbd.release(keycodePress)
if switch.fell:
kbd.press(keycodePress)