Created
October 26, 2023 06:12
-
-
Save suzumura-ss/eefefc6a3d5f68c101c580f6e9b07bcf to your computer and use it in GitHub Desktop.
send string example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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