using esb32 by Espress Systems Ver 2.0.7 otherwise my code dose not work with 3.0.5
Code: Select all
#include <BleKeyboard.h>
// Define pin numbers for the buttons
const int BUTTON_o_PIN = 12; // Pin for Button L
const int BUTTON_p_PIN = 13; // Pin for Button P
// Create a BleKeyboard object
BleKeyboard bleKeyboard("Shifter");
void setup() {
// Initialize Serial for debugging
Serial.begin(115200);
// Initialize the BLE keyboard
bleKeyboard.begin();
// Set button pins as input with pull-up resistor
pinMode(BUTTON_o_PIN, INPUT_PULLUP);
pinMode(BUTTON_p_PIN, INPUT_PULLUP);
}
void loop() {
// Read the current state of the buttons
bool currentButtonLState = digitalRead(BUTTON_o_PIN) == LOW; // LOW means pressed
bool currentButtonPState = digitalRead(BUTTON_p_PIN) == LOW; // LOW means pressed
// Button L logic
if (currentButtonLState) {
bleKeyboard.press('o'); // Send key press for 'o'
Serial.println("Button L Pressed");
delay(100); // debounce delay
} else {
bleKeyboard.release('o'); // Release key for 'o'
}
// Button P logic
if (currentButtonPState) {
bleKeyboard.press('p'); // Send key press for 'p'
Serial.println("Button P Pressed");
delay(100); // debounce delay
} else {
bleKeyboard.release('p'); // Release key for 'p'
}
// Optional: Small delay to mitigate excessive keypresses
delay(10);
}