mirror of
https://github.com/lemmingDev/ESP32-BLE-Gamepad.git
synced 2026-03-25 09:26:59 +01:00
The examples and readme treated R/L triggers as signed chars, however they are now correctly referenced as chars (0 ~ 255) The HID descriptor was correct, but now people using the library will have a better chance of using the triggers correctly ;)
43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
#include <Bounce2.h> // https://github.com/thomasfredericks/Bounce2
|
|
#include <BleGamepad.h> // https://github.com/lemmingDev/ESP32-BLE-Gamepad
|
|
|
|
#define BUTTON_PIN 2
|
|
#define LED_PIN 13
|
|
|
|
Bounce debouncer = Bounce(); // Instantiate a Bounce object
|
|
BleGamepad bleGamepad; // Instantiate a BleGamepad object
|
|
|
|
void setup()
|
|
{
|
|
bleGamepad.begin(); // Begin the gamepad
|
|
|
|
pinMode(BUTTON_PIN, INPUT_PULLUP); // Setup the button with an internal pull-up
|
|
|
|
debouncer.attach(BUTTON_PIN); // After setting up the button, setup the Bounce instance :
|
|
debouncer.interval(5); // interval in ms
|
|
|
|
pinMode(LED_PIN, OUTPUT); // Setup the LED :
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
if(bleGamepad.isConnected())
|
|
{
|
|
debouncer.update(); // Update the Bounce instance
|
|
|
|
int value = debouncer.read(); // Get the updated value
|
|
|
|
// Press gamepad button and turn on or off the LED as determined by the state
|
|
if (value == LOW)
|
|
{
|
|
digitalWrite(LED_PIN, HIGH);
|
|
bleGamepad.press(BUTTON_1);
|
|
}
|
|
else
|
|
{
|
|
digitalWrite(LED_PIN, LOW);
|
|
bleGamepad.release(BUTTON_1);
|
|
}
|
|
}
|
|
}
|