Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
CircuitPython code for sending USB media controls with a foot pedal
import board # Lists the pin names for the board we're using
from time import sleep
# Set up the USB Human Interface Device (HID) libraries
import usb_hid
from adafruit_hid.consumer_control import ConsumerControl
from adafruit_hid.consumer_control_code import ConsumerControlCode
consumer_control = ConsumerControl(usb_hid.devices)
# Set up the analog input pin to read the pedal state
from analogio import AnalogIn
pedal = AnalogIn(board.A7)
# Loop forever, reading the pedal value
while True:
# The pedal value will be between ~35,000 (unpressed) and ~10,000 (fully pressed)
if pedal.value < 15000:
# We detected the pedal was pressed, so send the Play/Pause command over USB:
# Stop reading for a second to prevent double-presses:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment