// Minimal leaning pedal firmware for Arduino (Pro) Micro // // You need two pedals with a 3 connector microswitch: COM, NC, NO // eg: https://www.aliexpress.com/item/4000136261950.html // // Wire it up as follows: // - Arduino input PIN (in code LEFT_PEDAL, RIGHT_PEDAL) -> COM // - VCC -> 10kOhm resistor -> NC // - GND -> NO // // This code is currently configured for the default PUBG leaning keys (q,e) but you can // change it for whatever you want (LEFT_KEY, RIGHT_KEY constants). // // If you use Platform I/O, the following ini file is required, // then you can paste this into main.cpp: // // [env:micro] // platform = atmelavr // board = micro // framework = arduino // lib_deps = // Keyboard #include #include char LEFT_KEY = 'Q'; char RIGHT_KEY = 'E'; int DEBOUNCE_DELAY = 50; int LEFT_PEDAL = 15; int RIGHT_PEDAL = 20; unsigned long currentMillis = 0; int leftState = LOW; int rightState = LOW; int leftKeyState = -1; int rightKeyState = -1; unsigned long leftLastDebounceTime = 0; unsigned long rightLastDebounceTime = 0; void setup() { Keyboard.begin(); pinMode(LEFT_PEDAL, INPUT); pinMode(RIGHT_PEDAL, INPUT); } void loop() { currentMillis = millis(); leftState = digitalRead(LEFT_PEDAL); rightState = digitalRead(RIGHT_PEDAL); // Handle left pedal debounced if ((currentMillis - leftLastDebounceTime) > DEBOUNCE_DELAY) { if (leftState == LOW && leftKeyState == -1) { // Left pedal was pressed Keyboard.press(LEFT_KEY); leftLastDebounceTime = currentMillis; leftKeyState = -leftKeyState; } else if (leftState == HIGH && leftKeyState == 1) { // Left pedal was released Keyboard.release(LEFT_KEY); leftLastDebounceTime = currentMillis; leftKeyState = -leftKeyState; } } // Handle right pedal debounced if ((currentMillis - rightLastDebounceTime) > DEBOUNCE_DELAY) { if (rightState == LOW && rightKeyState == -1) { // Right pedal was pressed Keyboard.press(RIGHT_KEY); rightLastDebounceTime = currentMillis; rightKeyState = -rightKeyState; } else if (rightState == HIGH && rightKeyState == 1) { // Right pedal was released Keyboard.release(RIGHT_KEY); rightLastDebounceTime = currentMillis; rightKeyState = -rightKeyState; } } }