1 of 3 buttons are backward.

I am having a small issue with my code. This works but one of my buttons are backwards (pin2). pin 2 is a hall effect sensor that needs to be open with magnet near and closed while magnet is away. pin 3 is a hall effect sensor working correctly. pin 4 is a button working correctly. If someone could help me fix it so all buttons work correctly. Thank you.

#include <Joystick.h>

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,
  3, 0,                  // Button Count, Hat Switch Count
  false, false, false,     // X and Y, but no Z Axis
  false, false, false,   // No Rx, Ry, or Rz
  false, false,          // No rudder or throttle
  false, false, false);  // No accelerator, brake, or steering

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

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

// Constant that maps the phyical pin to the joystick button.
const int pinToButtonMap = 2;

// Last state of the button
int lastButtonState[3] = {0,0,0};

void loop() {
// Read pin values
  for (int index = 0; index < 3; index++)
  {
    int currentButtonState = !digitalRead(index + pinToButtonMap);
    if (currentButtonState != lastButtonState[index])
    {
      Joystick.setButton(index, currentButtonState);
      lastButtonState[index] = currentButtonState;
    }
  }

  delay(50);
}

If one is not wired / working like the others, you just can’t apply the same logic to the 3 of them.. you need to add a if to check if you are at the index of the weird one to inverse the logic for example (or as you have only 3, unwind the for loop and write the code 3 times with the right tests

I fixed it. Thank you. Now I just need to figure out how to rename the device so it shows Button box or Mega Shifter instead of Arduino Micro.