bluetooth issue having to re pair each time
Posted: Fri Sep 27, 2024 2:22 pm
dont know if anyone can help.... im having an issue with bluetooth with my esp32, it connects to windows and my code works fine, untill i dissconnect the power to the esp32, if i reconnect the power it connects to windows fine as it was paired, but it wont then send the key presses unless i un pair and re pair again?
using esb32 by Espress Systems Ver 2.0.7 otherwise my code dose not work with 3.0.5
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);
}