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.
This commit is contained in:
parent
c7eeeda506
commit
224e778b8e
1 changed files with 31 additions and 3 deletions
|
|
@ -14,13 +14,41 @@ void setup() {
|
||||||
pinMode(buttonPin, INPUT_PULLUP);
|
pinMode(buttonPin, INPUT_PULLUP);
|
||||||
Gamepad.begin();
|
Gamepad.begin();
|
||||||
USB.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() {
|
void loop() {
|
||||||
|
static uint8_t padID = 0;
|
||||||
|
static long lastPress = 0;
|
||||||
|
|
||||||
int buttonState = digitalRead(buttonPin);
|
int buttonState = digitalRead(buttonPin);
|
||||||
if ((buttonState != previousButtonState) && (buttonState == LOW)) {
|
if (buttonState != previousButtonState) {
|
||||||
Gamepad.pressButton(BUTTON_START);
|
if (buttonState == LOW) { // BOOT Button pressed
|
||||||
Gamepad.releaseButton(BUTTON_START);
|
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;
|
previousButtonState = buttonState;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue