Unverified Commit 224e778b authored by Rodrigo Garcia's avatar Rodrigo Garcia Committed by GitHub

Makes Gamepad example able to be tested with Windows 10/11 (#8058)

* Makes sure it can be tested with Windows 10/11

Initial code had no effect with Win10/11 because BUTTON_START was not recognized.
This change makes it visible in the Windows Game Controller Testing TAB.

* Examples tests all USB gamepad APIs.

It is possible to change the selected gamepad button when pressing BOOT (long/short press).
The selected button is used as parameter to change R/L Stick and Trigger as well as the Hat.
parent c7eeeda5
......@@ -14,13 +14,41 @@ void setup() {
pinMode(buttonPin, INPUT_PULLUP);
Gamepad.begin();
USB.begin();
Serial.begin(115200);
Serial.println("\n==================\nUSB Gamepad Testing\n==================\n");
Serial.println("Press BOOT Button to activate the USB gamepad.");
Serial.println("Longer press will change the affected button and controls.");
Serial.println("Shorter press/release just activates the button and controls.");
}
void loop() {
static uint8_t padID = 0;
static long lastPress = 0;
int buttonState = digitalRead(buttonPin);
if ((buttonState != previousButtonState) && (buttonState == LOW)) {
Gamepad.pressButton(BUTTON_START);
Gamepad.releaseButton(BUTTON_START);
if (buttonState != previousButtonState) {
if (buttonState == LOW) { // BOOT Button pressed
Gamepad.pressButton(padID); // Buttons 1 to 32
Gamepad.leftStick(padID << 3, padID << 3); // X Axis, Y Axis
Gamepad.rightStick(-(padID << 2), padID << 2); // Z Axis, Z Rotation
Gamepad.leftTrigger(padID << 4); // X Rotation
Gamepad.rightTrigger(-(padID << 4)); // Y Rotation
Gamepad.hat((padID & 0x7) + 1); // Point of View Hat
log_d("Pressed PadID [%d]", padID);
lastPress = millis();
} else {
Gamepad.releaseButton(padID);
Gamepad.leftStick(0, 0);
Gamepad.rightStick(0, 0);
Gamepad.leftTrigger(0);
Gamepad.rightTrigger(0);
Gamepad.hat(HAT_CENTER);
log_d("Released PadID [%d]\n", padID);
if (millis() - lastPress > 300) {
padID = (padID + 1) & 0x1F;
log_d("Changed padID to %d\n", padID);
}
}
}
previousButtonState = buttonState;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment