Files
ESP32-BLE-Gamepad/examples/SingleButtonDebounce/SingleButtonDebounce.ino
lemmingDev 34fb08f70e Updated examples and Readme
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 ;)
2020-11-22 08:49:08 +10:00

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);
}
}
}