Sure, allow me to clarify. I've also added the schematics to the button in question. But it's a switch with its own separate contacts internally. Similar to the function of a gamepad. Here in the schematic, you can see it has 6 paths, I'm only utilizing 5 of the paths since I will not be using the center pushbutton. But the paths being used are A,B,C,D, Common.
#include <HID_Buttons.h>
//BUTTON BOX
//USE w ProMicro
//Tested in WIN10 + Assetto Corsa
//AMSTUDIO
//20.8.17
#include <Keypad.h>
#include <Joystick.h>
#define ENABLE_PULLUPS
#define NUMBUTTONS 31
#define NUMROWS 6
#define NUMCOLS 6
byte buttons[NUMROWS][NUMCOLS] = {
{0, 1, 2, 3, 4, 5},
{6, 7, 8, 9, 10, 11},
{12,13,14, 15},
{16,17,18, 19, 20},
{21,22,23, 24, 25},
{26,27,28, 29, 30}
};
byte rowPins[NUMROWS] = {8,9,10,14,16,15};
byte colPins[NUMCOLS] = {2,3,4,5,6,7};
Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK, 31, 0,
false, false, true, true, true, true,
false, false, false, false, false);
const int numReadings = 20;
int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int currentOutputLevel = 0;
//POTENTIOMETERS PART 1
//add all the axis' which are enabled above
int zAxis_ = 0;
int RxAxis_ = 0;
int RyAxis_ = 0;
int RzAxis_ = 0;
//POTENTIOMETERS PART 2
//Which pins are your potentiometers connected to?
int potentiometerPin1 = A0; //Change "?" to the pin your potentiometer is connected to
int potentiometerPin2 = A1;
int potentiometerPin3 = A2;
int potentiometerPin4 = A3;
const bool initAutoSendState = true;
void setup() {
Joystick.begin();
}
void loop() {
CheckAllPotentiometers();
CheckAllButtons();
}
//POTENTIOMETERS PART 3
//change the details to match teh details above for each potentiometer you are using
void CheckAllPotentiometers(){
//potentiometer 1
currentOutputLevel = getAverageOutput(potentiometerPin1);
zAxis_ = map(currentOutputLevel,0,1023,0,255);
Joystick.setZAxis(zAxis_);
//potentiometer 2
currentOutputLevel = getAverageOutput(potentiometerPin2);
RxAxis_ = map(currentOutputLevel,0,1023,0,255);
Joystick.setRxAxis(RxAxis_);
//potentiometer 3
currentOutputLevel = getAverageOutput(potentiometerPin3);
RyAxis_ = map(currentOutputLevel,0,1023,0,255);
Joystick.setRyAxis(RyAxis_);
//potentiometer 4
currentOutputLevel = getAverageOutput(potentiometerPin4);
RzAxis_ = map(currentOutputLevel,0,1023,0,255);
Joystick.setRzAxis(RzAxis_);
}
int getAverageOutput(int pinToRead){
index = 0;
total = 0;
while (index < numReadings){
readings[index] = analogRead(pinToRead);
total = total + readings[index];
index = index + 1;
//delay (1);
}
return total / numReadings;
}
void CheckAllButtons(void) {
if (buttbx.getKeys())
{
for (int i=0; i<LIST_MAX; i++)
{
if ( buttbx.key[i].stateChanged )
{
switch (buttbx.key[i].kstate) {
case PRESSED:
case HOLD:
Joystick.setButton(buttbx.key[i].kchar, 1);
break;
case RELEASED:
case IDLE:
Joystick.setButton(buttbx.key[i].kchar, 0);
break;
}
}
}
}
}