Need help with Arduino Joystick library and Limit Switch

Hello !

I want to connect two Limit Switch for an Joystick and Arduino Pro micro board.

I used this Joystick library : GitHub - 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.

The wiring :

The arduino Sketch :

#include <Joystick.h>

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD, 
2, 0,                // Button Count, Hat Switch Count
false, false, false,  // 3 mores analogs inputs (for potentiometers for exemple). Set them to "true" if you need them.
false, false, false,     // Rx (potentiometer), Ry (Brake loadcell), Rz (potentiometers)
false, false,         // Rudder, throttle
false, false, false); // Accelerator, brake, stering


void setup() {
  
  Joystick.begin();
  Serial.begin(38400);

  // Buttons
  pinMode(2, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
}

void loop() {
  Joystick.setButton(0, !digitalRead(2));
  Joystick.setButton(1, !digitalRead(4));
  delay(50);
} // End loop

But it's not working ! When I push the limit switch I have nothing in my Joystick.

Can you help me ? Thanks.

Switches should go to ground not vcc..

good luck.. ~q

1 Like

Thanks, but there is 3 GND holes, which is the good ?

take you pick, their all the same.. :slight_smile:
~q

1 Like

your pinMode is INPUT_PULLUP, means they start HIGH..
Just need to bring the pin to ground to get a low..
otherwise, always HIGH..

~q

1 Like

Thanks, I will try the 3 GND.

It worked !! Thanks you qubits-us :smiley:

1 Like

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