Skip to content

Instantly share code, notes, and snippets.

@suzumura-ss
Created October 26, 2023 06:12
Show Gist options
  • Save suzumura-ss/eefefc6a3d5f68c101c580f6e9b07bcf to your computer and use it in GitHub Desktop.
Save suzumura-ss/eefefc6a3d5f68c101c580f6e9b07bcf to your computer and use it in GitHub Desktop.
send string example
import board
from digitalio import DigitalInOut, Pull
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayout
kbd = Keyboard(usb_hid.devices)
layout = KeyboardLayout(kbd)
class Button:
def __init__(self, pin, text):
self.btn = DigitalInOut(pin)
self.btn.switch_to_input(Pull.UP)
self.last = self.btn.value
self.text = text
def process(self):
value = self.btn.value
if value != self.last:
if not value:
layout.write(self.text)
self.last = value
button1 = Button(board.GP14, "hello")
button2 = Button(board.GP15, "world")
while True:
button1.process()
button2.process()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment