Created
February 8, 2022 06:33
-
-
Save will-hart/45090e7d43fe5d6656ce9fc78dbceb27 to your computer and use it in GitHub Desktop.
Firmware for custom footpedals using "blue pill" STM32 boards
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
#include <USBComposite.h> | |
#define LEAN_LEFT_CHAR 'q' | |
#define LEAN_RIGHT_CHAR 'e' | |
#define LEAN_LEFT PA9 | |
#define LEAN_RIGHT PA10 | |
#define LED_PIN PC13 | |
USBHID HID; | |
HIDKeyboard Keyboard(HID); | |
bool leftIsPressed = false; | |
bool rightIsPressed = false; | |
void setup() { | |
pinMode(LEAN_LEFT, INPUT_PULLUP); | |
pinMode(LEAN_RIGHT, INPUT_PULLUP); | |
USBComposite.setManufacturerString("Wilsk"); | |
USBComposite.setProductString("Pico Foot Pedal"); | |
USBComposite.setSerialString("00000000000000000001"); | |
USBComposite.setProductId(0xbeef); | |
USBComposite.setVendorId(0x7337); | |
HID.begin(HID_KEYBOARD); | |
while (!USBComposite); | |
pinMode(LED_PIN, OUTPUT); | |
digitalWrite(LED_PIN, LOW); | |
Keyboard.begin(); | |
} | |
void loop() { | |
leftIsPressed = updateButtonState(!digitalRead(LEAN_LEFT), leftIsPressed, LEAN_LEFT_CHAR); | |
rightIsPressed = updateButtonState(!digitalRead(LEAN_RIGHT), rightIsPressed, LEAN_RIGHT_CHAR); | |
digitalWrite(LED_PIN, !(leftIsPressed || rightIsPressed)); | |
delay(100); | |
} | |
bool updateButtonState(bool isActive, bool currentState, char keyCode) { | |
if (isActive && !currentState) { | |
// just pressed | |
Keyboard.press(keyCode); | |
return !currentState; | |
} | |
if (!isActive && currentState) { | |
// just went low | |
Keyboard.release(keyCode); | |
return !currentState; | |
} | |
// otherwise do nothing | |
return currentState; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment