commit 87a8eb98e3990fd37898755416a894d3e4b10ea8 Author: Kumi Date: Tue Oct 22 15:22:28 2024 +0200 feat: add Arduino sketch for ESP32 BLE footswitch Introduced an Arduino sketch utilizing the BleKeyboard library, enabling keypress transmission from an ESP32 via BLE upon footswitch activation. Configured GPIO 25 for connection and assumed a normally open footswitch design. This setup facilitates toggling microphone status using a predefined key in KDE Plasma, enhancing user control. The inclusion of README.md provides setup context and operational guidance. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e2ddf95 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# ESP32 BLE Footswitch + +This is a really simple Arduino IDE sketch that uses the [BleKeyboard library](https://github.com/T-vK/ESP32-BLE-Keyboard/) to send a keypress from an ESP32 to your PC via Bluetooth Low Energy when a footswitch is activated. + +The footswitch is connected to ground and GPIO 25 on the ESP32, because that was the most convenient option for me, using a [D1 Mini from AZ-Delivery](https://www.az-delivery.de/products/esp32-d1-mini) and 5mm 2-pin screw terminals. + +I used a generic footswitch that I had lying around, those are available at your favorite electronics store or online for a few euros. The sketch assumes that the footswitch is normally open and closes the circuit when pressed. If you have a normally closed footswitch, you can just update the sketch accordingly. + +The sketch sends the "Bookmarks" media key both when it is pressed and when it is released. I chose that key because it was unused on my system and others (like F18) didn't seem to work for some reason. I then added a shortcut in KDE Plasma to trigger the action I wanted when that keypress is received, which was to toggle the microphone on and off. This way, I can have my microphone muted by default and only enable it temporarily while I'm speaking. diff --git a/footswitch.ino b/footswitch.ino new file mode 100644 index 0000000..cfade5d --- /dev/null +++ b/footswitch.ino @@ -0,0 +1,34 @@ +#include + +#define USE_NIMBLE 1 + +BleKeyboard bleKeyboard("Footswitch", "Kumi", 100); + +#define SWITCH_PIN 25 + +void setup() { + pinMode(SWITCH_PIN, INPUT_PULLUP); + bleKeyboard.begin(); +} + +void loop() { + static bool wasPressed = false; + + // Check if any device is connected + if (bleKeyboard.isConnected()) { + bool isPressed = !digitalRead(SWITCH_PIN); + + // Execute on footswitch press + if (isPressed && !wasPressed) { + bleKeyboard.write(KEY_MEDIA_WWW_BOOKMARKS); + wasPressed = true; + } + // And then again on release + else if (!isPressed && wasPressed) { + bleKeyboard.write(KEY_MEDIA_WWW_BOOKMARKS); + wasPressed = false; + } + } + + delay(10); // Delay for debouncing +}