mirror of
https://github.com/lemmingDev/ESP32-BLE-Gamepad.git
synced 2026-03-10 01:56:58 +01:00
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
37 lines
676 B
C++
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;
|
|
}
|
|
} |