Created
July 12, 2020 19:07
-
-
Save tylercrumpton/c2ae1746c7dc0a5f02aad2121c7933d3 to your computer and use it in GitHub Desktop.
CircuitPython code for sending USB media controls with a foot pedal
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 # 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: | |
consumer_control.send(ConsumerControlCode.PLAY_PAUSE) | |
# Stop reading for a second to prevent double-presses: | |
sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment