Skip to content

Instantly share code, notes, and snippets.

@JeremySCook
Created October 4, 2022 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeremySCook/6ce1a6495154c66b890247bded9212ee to your computer and use it in GitHub Desktop.
Save JeremySCook/6ce1a6495154c66b890247bded9212ee to your computer and use it in GitHub Desktop.
basic macro pad on RP2040
import time
import digitalio
import board
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
btn1_pin = board.GP5
btn2_pin = board.GP6
btn3_pin = board.GP7
keyboard = Keyboard(usb_hid.devices)
btn1 = digitalio.DigitalInOut(btn1_pin)
btn1.direction = digitalio.Direction.INPUT
btn1.pull = digitalio.Pull.UP
btn2 = digitalio.DigitalInOut(btn2_pin)
btn2.direction = digitalio.Direction.INPUT
btn2.pull = digitalio.Pull.UP
btn3 = digitalio.DigitalInOut(btn3_pin)
btn3.direction = digitalio.Direction.INPUT
btn3.pull = digitalio.Pull.UP
while True:
if not btn1.value:
print("button 1 pressed")
keyboard.press(Keycode.LEFT_CONTROL, Keycode.TAB)
time.sleep(0.2)
keyboard.release(Keycode.LEFT_CONTROL, Keycode.TAB)
if not btn2.value:
print("button 2 pressed")
keyboard.press(Keycode.LEFT_CONTROL, Keycode.LEFT_SHIFT,Keycode.TAB)
time.sleep(0.2)
keyboard.release(Keycode.LEFT_CONTROL, Keycode.LEFT_SHIFT,Keycode.TAB)
if not btn3.value:
print("button 3 pressed")
keyboard.press(Keycode.ENTER)
time.sleep(0.2)
keyboard.release(Keycode.ENTER)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment