Duplicate button utilized on button box

Requesting assistance, just created a box to use as a gamepad/joystick for gaming purposes. It contains potentiometers, pushbuttons, and multiple SPDT switches, and a 5-way push button.
I'm utilizing a 6x6 matrix as you can see in the image below to allow the 31 buttons configuration. Problem I'm facing is two sets of buttons are utilizing the same button respectively for instance x & y using button 8, and xx & yy using button 18 during the functional check using the joy.cpl on windows. This is leaving buttons 12 & 21 not in use.

What I believe is my problem is the 5-way push button that is listed and trying to wire/program that correctly in the sketch. I'm only using 4 of the 5-way function, but two of the buttons is working correctly. Would like to hear some advice in this.

The image below is a snapshot of how I have it wired in a schematic and how I have it coded in the IDE.

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

I note that you have used a value of zero in the keypad array. This is not likely to work because the Keypad library returns zero from some functions to indicate that no key has been pressed

Please explain exactly what you mean by a 5-way pushbutton switch. Is it a set of 5 locking pushbuttons such that only one can be pressed at a time ? If so, then what is the purpose of it in your project ?

Good afternoon and thank you for the quick response. I have added an image of the 5-way push button. But it's a push button with four directional and a center push button. For the project I'm using it for it will only be needed to push one directional button at a time as needed.

Also, changed to see if removing the zero and adding everything over one number, still having the same issue.

I still can't make any sense of your description of the switch. IS it actually a 4 way rotary switch that moves a contact to one of four others and a completely separate pushbutton switch with its own separate contacts

Not using zero will not solve your immediate problem but it will stop future ones

Please post your full sketch

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;
            }
           }   
         }
     }
}

Thanks for the attempt, decided to relook into re-wiring and changed to a 4x8 matrix. Had some issues, apparently one of the pins decided not to work, that was the cause of a bunch of the issues. Cheers,

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