Created
May 25, 2026 20:54
-
-
Save todbot/94a81da36c123c546599c295996fc73c to your computer and use it in GitHub Desktop.
USB HID Keyboard LED emulator in CircuitPython
This file contains hidden or 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 time | |
| import usb_hid | |
| import adafruit_hid | |
| keyboard_hid = adafruit_hid.find_device(usb_hid.devices, usage_page=1, usage=6) | |
| print("waiting for LED commands from computer") | |
| while True: | |
| out_report = keyboard_hid.get_last_received_report() # out from computer | |
| if out_report: | |
| print(["%02x" % x for x in out_report]) | |
| time.sleep(0.5) | |
| # Note in Linux you can then toggle the LEDs with: | |
| # echo "1" | sudo tee -a /sys/class/leds/input41::scrolllock/brightness | |
| # echo "0" | sudo tee -a /sys/class/leds/input41::scrolllock/brightness | |
| # and "input41" will change depending on when and where you plug in your CircuitPython device. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment