Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Maker Nano RP2040 four keys keyboard
# Raspberry Pi Pico Keyboard Demo
# Using CircuitPython https://circuitpython.org/board/cytron_maker_nano_rp2040/
# Using Adafruit USB_HID Library https://circuitpython.org/libraries
# Based on DroneBot Workshop 2021 https://dronebotworkshop.com
# Modified by Panan for Demo at DIY keyboard project https://www.youtube.com/watch?v=iChTO2C1c9g&list=PL9K9tbjCONeziZt7By7gRklBIlKdFnC85
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
keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard)
btn1 = digitalio.DigitalInOut(board.GP16)
btn1.direction = digitalio.Direction.INPUT
btn1.pull = digitalio.Pull.DOWN
btn2 = digitalio.DigitalInOut(board.GP19)
btn2.direction = digitalio.Direction.INPUT
btn2.pull = digitalio.Pull.DOWN
btn3 = digitalio.DigitalInOut(board.GP17)
btn3.direction = digitalio.Direction.INPUT
btn3.pull = digitalio.Pull.DOWN
btn4 = digitalio.DigitalInOut(board.GP9)
btn4.direction = digitalio.Direction.INPUT
btn4.pull = digitalio.Pull.DOWN
while True:
if btn1.value:
keyboard.press(Keycode.Q)
time.sleep(0.1)
keyboard.release(Keycode.Q)
if btn2.value:
keyboard.press(Keycode.W)
time.sleep(0.1)
keyboard.release(Keycode.W)
if btn3.value:
keyboard.press(Keycode.E)
time.sleep(0.1)
keyboard.release(Keycode.E)
if btn4.value:
keyboard.press(Keycode.R)
time.sleep(0.1)
keyboard.release(Keycode.R)
time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment