Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 10, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions libraries/USB/examples/Gamepad/Gamepad.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ void loop(){}
#include "USBHIDGamepad.h"
USBHIDGamepad Gamepad;

const int buttonPin = 0;
// This sketch works correctly for the ESP32-S2 and ESP32-S3 in OTG mode (TinyUSB)

const int buttonPin = 0; // GPIO 0 is the BOOT button of the board
int previousButtonState = HIGH;

void setup() {
Expand All @@ -18,9 +20,14 @@ void setup() {

void loop() {
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
// changes many states
Gamepad.send(-100, 100, 50, 100, -100, -50, HAT_DOWN_RIGHT, BUTTON_TL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last argument here is mask, so correct value would be (1 << BUTTON_TL).

} else {
// restores neutral states
Gamepad.send(0, 0, 0, 0, 0, 0, 0, 0);
}
}
previousButtonState = buttonState;
}
Expand Down