MHeironimus / ArduinoJoystickLibrary

An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.
GNU Lesser General Public License v3.0
2.07k stars 403 forks source link

press more than one button at the same time #157

Open nicolascuadra opened 3 years ago

nicolascuadra commented 3 years ago

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_ 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) }

byteborg commented 3 years ago

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.