One of the projects that I have been meaning to work on for a while is a foot pedal to use with discord, which for those that are not aware is a text and voice communications application. Most of the time when I am using discord for voice communications, I don't really want to be using a push-to-talk key to be able to talk to people, mostly because I'm usually busy pushing other keys on the keyboard. My original plan was to use an arduino, but then I found out about the RaspberryPi Pico.
The appealing thing to me about the Pico is that it can run python code. So I ordered a couple of Picos, snagged a generic footswitch off of amazon, and waited for the parts to arrive.
Since I don't have anything to use as a case currently, I soldered the two wires directly to the board, and then used some string through the mounting holes to secure the board to the end of the cord from the pedal.
The code was pretty simple after reading the documentation for the adafruit_hid library. Whenever I use the footswitch, it sends the keypress for the menu, or application, key.
EDIT 2021-09-29: Discord wouldn't let me use the Keycode.APPLICATION anymore, so after some trial and error I was able to use Keycode.F24 instead.
import time import digitalio import board import usb_hid from adafruit_hid.keyboard import Keyboard from adafruit_hid.keyboard import Keycode keyboard = Keyboard(usb_hid.devices) led = digitalio.DigitalInOut(board.GP25) led.direction = digitalio.Direction.OUTPUT led.value = False foot_switch = digitalio.DigitalInOut(board.GP0) foot_switch.direction = digitalio.Direction.INPUT foot_switch.pull = digitalio.Pull.DOWN while True: if foot_switch.value: led.value = True # keyboard.press(Keycode.APPLICATION) keyboard.press(Keycode.F24) else: # keyboard.release(Keycode.APPLICATION) keyboard.release(Keycode.F24) led.value = False time.sleep(0.1)