Files
ESP32-BLE-Gamepad/examples/SingleButton/SingleButton.ino
lemmingDev 3018600dbd 32 buttons and X,Y,Z and rZ axes are now 16 bit
Library now supports 32 buttons
X,Y,Z and rZ axes are now 16 bit int16_t (-32767 to 32767) instead of 8 bit (-127 to 127)

If you're upgrading, remember to account for this when setting your axes values
2020-11-28 13:43:27 +10:00

37 lines
676 B
C++

/*
* A simple sketch that maps a single pin on the ESP32 to a single button on the controller
*/
#include <BleGamepad.h> // https://github.com/lemmingDev/ESP32-BLE-Gamepad
BleGamepad bleGamepad;
int previousButton1State = HIGH;
void setup()
{
pinMode(2, INPUT_PULLUP);
bleGamepad.begin();
}
void loop()
{
if(bleGamepad.isConnected())
{
int currentButton1State = digitalRead(2);
if (currentButton1State != previousButton1State)
{
if(currentButton1State == LOW)
{
bleGamepad.press(BUTTON_1);
}
else
{
bleGamepad.release(BUTTON_1);
}
}
previousButton1State = currentButton1State;
}
}