Change button number?

Ok, I’ve been working on finding a way to get my computer to recognize the board I am using as a game controller and I finally did it. I have also got it recognizing when I throw the switch as being button one being pushed (and no others…I had trouble with that for a while).

BUT I have another joystick with 5 buttons and then one more controller with 9 buttons or so. What I need to do is get the new switch to be recognized as button 15.

I have the switch wired to D3 and GND. Here is my code, please let me know how to accomplish this.

// Simple example application that shows how to read four Arduino
// digital pins and map them to the USB Joystick library.
//
// Ground digital pins 9, 10, 11, and 12 to press the joystick 
// buttons 0, 1, 2, and 3.
//
// NOTE: This sketch file is for use with Arduino Leonardo and
//       Arduino Micro only.
//
// by Matthew Heironimus
// 2015-11-20
//--------------------------------------------------------------------

#include <Joystick.h>

Joystick_ Joystick;

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


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

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

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

void loop() {

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

  delay(50);
}

Change the for loop to process more buttons.

DrDiettrich:
Change the for loop to process more buttons.

Got it! Thanks. I actually managed to get that earlier today with trial and error.

Fine :slight_smile: