ArduinoJoystickLibrary icon indicating copy to clipboard operation
ArduinoJoystickLibrary copied to clipboard

press more than one button at the same time

Open nicolascuadra opened this issue 5 years ago • 1 comments

i made mi arduino pro micro work, windows recognize it as joystick and buttons works fine, but when 2 bottons pressed windows shows all buttons not pressed. is this a problem with mi code ? or the arduino pins?, if pin 3 is set to ground or button 2 is pressed when button 1 is pressed , win shows all buttons released...

#include <Joystick.h>

Joystick_ Joystick;

void setup() { // Initialize Button Pins pinMode(2, INPUT_PULLUP); pinMode(3, INPUT_PULLUP); pinMode(4, INPUT_PULLUP); pinMode(5, INPUT_PULLUP); pinMode(6, INPUT_PULLUP);

// Initialize Joystick Library Joystick.begin(); }

void loop() {

if (digitalRead(2)== LOW){ Joystick.pressButton(1); }else{ Joystick.releaseButton(1); }

if (digitalRead(3)== LOW){ Joystick.pressButton(2); }else{ Joystick.releaseButton(2); } delay(10) }

nicolascuadra avatar Aug 15 '20 02:08 nicolascuadra

Have you tried sending the state every loop, not every invocation of a method?

void setup() {
  ...
  Joystick.begin(false);
}

voice loop() {
  ...
  Joystick.sendState();
  delay(10);
}

You could also use Joystick.setButton(2, digitalRead(3)); instead of if/else. I'd debounce the buttons first. There are good libs for that.

byteborg avatar Oct 10 '20 17:10 byteborg