dmadison / ArduinoXInput

XInput library for USB capable Arduino boards
http://www.partsnotincluded.com/arduino-xinput-library/
MIT License
361 stars 61 forks source link

Toggle left/right analog stick #62

Closed crowcey closed 1 year ago

crowcey commented 2 years ago

New to all this, greatly appreciate your code and all your hard work.

Is there a way to use a switch to toggle a single joystick between left or right stick.

dmadison commented 2 years ago

Hi there. You can store the joystick ID in a variable, then change it as needed. Something like:

XInputControl joystick;

if(digitalRead(SwitchPin) == LOW) {
    joystick = JOY_LEFT;
}
else {
    joystick = JOY_RIGHT;
}

Then use the standard joystick 'set' function and pass the joystick variable as the ID.

crowcey commented 2 years ago

Thank you very much. Think that makes sense.

crowcey commented 1 year ago

Can you do the same with the push buttons. I've tried every combination but can't wrap my head round it.

dmadison commented 1 year ago

Yes, in exactly the same way:

XInputControl button;

if(digitalRead(SwitchPin) == LOW) {
    button = BUTTON_A;
}
else {
    button = BUTTON_B;
}

XInput.setButton(button, state);
crowcey commented 1 year ago

BINGO!!! Thank you very much, I was close but just making a few blunders. Thanks for your help