Need help with synchronizing XInputs

I'm new to Arduino so if this is a stupid topic, then there's my excuse. Anyways, I am using an Arduino Micro and the ArduinoXInput Library (Github: GitHub - dmadison/ArduinoXInput: XInput library for USB capable Arduino boards). I am trying to have two XInputs happen at the same time when one button is pressed. It works most of the time, but every once in a while they desync and they happen one after another.

Here's the code in the loop():

if (digitalRead(12) == HIGH) {
  XInput.press(DPAD_UP);
  XInput.press(DPAD_RIGHT);
}
else if (digitalRead(12) == LOW) {
  XInput.release(DPAD_UP);
  XInput.release(DPAD_RIGHT);
}

Here's a .gif showing what's happening:

I repeatedly press one button on pin 12 and occasionally only one of the XInputs happen instead of two. (in the example, only the up XInput happens instead of both up and right XInputs)

The second clause is redundant. If something is HIGH, it can't be LOW.

Maybe try using this XInputController method instead of the press() method:

void setDpad(boolean up, boolean down, boolean left, boolean right, boolean useSOCD=true);

That is more likely to make sure that the two press events don't get split across USB updates.

We don't judge topics, but there is some expectation that you read the forum guidelines.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.