ESP32-BLE-Gamepad icon indicating copy to clipboard operation
ESP32-BLE-Gamepad copied to clipboard

Multiple gamepad 1 PC

Open sosssego opened this issue 6 months ago • 24 comments

I tried to use the BLE gamepad example from Arduino to make 2 gamepads and play cooperative games. The only difference in code is the name of the gamepad BleGamepad bleGamepad("Gamepad1"); BleGamepad bleGamepad("Gamepad2"); When trying to connect the second gamepad windows Failed and asked to try again. Trying again resulted in the same issue.

I used 2 generic ESP32 devkit V1.

Connecting the controllers alone works ok.

Is there anything else I need to change in the code between the 2 gamepads?

example code:

#include <Arduino.h>
#include <BleGamepad.h>

BleGamepad bleGamepad;

void setup()
{
    Serial.begin(115200);
    Serial.println("Starting BLE work!");
    bleGamepad.begin();
    // The default bleGamepad.begin() above enables 16 buttons, all axes, one hat, and no simulation controls or special buttons
}

void loop()
{
    if (bleGamepad.isConnected())
    {
        Serial.println("Press buttons 5, 16 and start. Move all enabled axes to max. Set DPAD (hat 1) to down right.");
        bleGamepad.press(BUTTON_5);
        bleGamepad.press(BUTTON_16);
        bleGamepad.pressStart();
        bleGamepad.setAxes(32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767);
        bleGamepad.setHat1(HAT_DOWN_RIGHT);
        // All axes, sliders, hats etc can also be set independently. See the IndividualAxes.ino example
        delay(500);

        Serial.println("Release button 5 and start. Move all axes to min. Set DPAD (hat 1) to centred.");
        bleGamepad.release(BUTTON_5);
        bleGamepad.releaseStart();
        bleGamepad.setHat1(HAT_CENTERED);
        bleGamepad.setAxes(0, 0, 0, 0, 0, 0, 0, 0);
        delay(500);
    }
}

sosssego avatar Aug 11 '24 23:08 sosssego