Button matrix is returning whole row instead of one button

I have been working on a button box so that i can play games with some cool controls
I have taken a lot of inspiration from this MAKE THIS BUTTON BOX | 32 FUNCTION w ENCODERS - YouTube
i am only using switches and buttons (now encoders)
i have managed to get a 6 button matrix working(2 rows 3 columns) using the joystick library and the keypad library. I have tested the 6 button code on the the 5*5 grid by only using 2 rows and 3 columns and that also worked meaning it is more than likely a problem with the code rather than anything else.
for some reason when i up the number of buttons and rows and test it the entire row responds for a single button or switch
all i did was copied the code form the 6 button matrix to the 25 button matrix and changed the values for the number of rows buttons and pins
pasted is the 6 button code, attached is the 25 button code that is not working

#include <Joystick.h>
#include <Keypad.h>


const byte rows = 2;
const byte cols = 3;

#define NUMBUTTONS 6
#define NUMROWS 2
#define NUMCOLS 3

byte keys[NUMROWS][NUMCOLS] = {
 {0, 1, 2},
 {3, 4, 5}
};

char key;
byte rowPins[rows] = {5, 6};
byte colPins[cols] = {7, 8, 9};

Keypad myKeypad = Keypad(makeKeymap(keys), rowPins, colPins, 2, 3);




Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
                  JOYSTICK_TYPE_JOYSTICK, 6, 0,
                  false, false, false, false, false, false,
                  false, false, false, false, false);



void setup() {
 // put your setup code here, to run once:
 Serial.begin(9600);
 Joystick.begin();
}

void loop() {


 if (myKeypad.getKeys())
 {
   for (int i = 0; i < NUMBUTTONS; i++)
   {
     if ( myKeypad.key[i].stateChanged )
     {
       switch (myKeypad.key[i].kstate) {
         case PRESSED:
         case HOLD:
           Joystick.setButton(myKeypad.key[i].kchar, 1);
           break;
         case RELEASED:
         case IDLE:
           Joystick.setButton(myKeypad.key[i].kchar, 0);
           break;
         
       }

     }
   }
 }
}

25 button code

#include <Joystick.h>
#include <Keypad.h>


const byte rows = 5;
const byte cols = 5;

#define NUMBUTTONS 25
#define NUMROWS 5
#define NUMCOLS 5

byte keys[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}

};


byte rowPins[rows] = {5, 6, 7, 8, 9};
byte colPins[cols] = {A0, 15, 14, 16, 10};

Keypad myKeypad = Keypad(makeKeymap(keys), rowPins, colPins, 5, 5);




Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
                   JOYSTICK_TYPE_JOYSTICK, 25, 0,
                   false, false, false, false, false, false,
                   false, false, false, false, false);



void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Joystick.begin();
}

void loop() {


  if (myKeypad.getKeys())
  {
    for (int i = 0; i < NUMBUTTONS; i++)
    {
      if ( myKeypad.key[i].stateChanged )
      {
        switch (myKeypad.key[i].kstate) {
          case PRESSED:
          case HOLD:
            Joystick.setButton(myKeypad.key[i].kchar, 1);
            Joystick.sendState();
            break;
          case RELEASED:
          case IDLE:
            Joystick.setButton(myKeypad.key[i].kchar, 0);
            Joystick.sendState();
            break;


        }

      }
    }

  }
}

3.2_25_buttons_dose_not_work.ino (1.34 KB)

Why do you have two sets of pin constant definitions?

const byte rows = 2;
const byte cols = 3;

#define NUMBUTTONS 6
#define NUMROWS 2
#define NUMCOLS 3

Then here you use neither of them:

Keypad myKeypad = Keypad(makeKeymap(keys), rowPins, colPins, 2, 3);

instead of

Keypad myKeypad = Keypad(makeKeymap(keys), rowPins, colPins, NUMROWS, NUMCOLS);

for example

You also neglected to use code tags for posting code, per the forum guidelines.

Sorry about the code markers, i didn't realise that you could and don't know how.
and for the other stuff i was using several different examples and must of crossed them over but it works for the 6 button matrix
i also just changed it around and it doesn't seem to have an effect

Then don't use several different examples. Start with one and modify it accordingly. It will be easier for both you and us.

It was just because of the two diffrent librarys, i got an example for each and combined them.
this is the changed 6 button code without the extra variables and it still seams to work
i changed the 25 button code and it dint make a difference either

3.1.1_6_button_does_work.ino (1.14 KB)

Do you think that combining two different library examples is such a good idea? Probably not. Why do you even need to do that?

Your sketch is small enough to post inline in code tags as previously requested, according to the forum guidelines. Complying with this simple protocol will attract more, and better quality help, because many more people will actually read the code.

Please post all your code this way, unless it is too big for the forum software to accept.

Thanks.

I have taken your advice for ditching the unnecessary variables but it didn't fix the problem,

the reason that i am using the two library's is because I tried to do it with just the joystick library in the beginning but it was overly complicated and so i found a tutorial on how to work the standard 4x4 button matrix

and when i got that to work i found how to make it interact with a computer and fond the joystick library (i also tried the keyboard library but this was not suitable for what i needed the button box for) in this vidio

and he also used the combination of the two,
i then made the 6 button prototype using both library's in the code using the joystick library to interact with the game pad software on the computer but when i tried changing the values of number of pins and actual input and output pins it returned an entire row instead of a single button to the game pad software on the computer

here is the code with the variables changed in both 6 button and 25 button codes

#include <Joystick.h>
#include <Keypad.h>




#define NUMBUTTONS 6
#define NUMROWS 2
#define NUMCOLS 3

byte keys[NUMROWS][NUMCOLS] = {
  {0, 1, 2},
  {3, 4, 5}
};


byte rowPins[NUMROWS] = {5, 6};
byte colPins[NUMCOLS] = {7, 8, 9};

Keypad myKeypad = Keypad(makeKeymap(keys), rowPins, colPins, NUMROWS, NUMCOLS);




Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
                   JOYSTICK_TYPE_JOYSTICK, 6, 0,
                   false, false, false, false, false, false,
                   false, false, false, false, false);



void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Joystick.begin();
}

void loop() {


  if (myKeypad.getKeys())
  {
    for (int i = 0; i < NUMBUTTONS; i++)
    {
      if ( myKeypad.key[i].stateChanged )
      {
        switch (myKeypad.key[i].kstate) {
          case PRESSED:
          case HOLD:
            Joystick.setButton(myKeypad.key[i].kchar, 1);
            break;
          case RELEASED:
          case IDLE:
            Joystick.setButton(myKeypad.key[i].kchar, 0);
            break;
          
        }

      }
    }
  }
}

and this is the 25 button code that doesn't work

#include <Joystick.h>
#include <Keypad.h>




#define NUMBUTTONS 25
#define NUMROWS 5
#define NUMCOLS 5

byte keys[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}

};


byte rowPins[NUMROWS] = {5, 6, 7, 8, 9};
byte colPins[NUMCOLS] = {A0, 15, 14, 16, 10};

Keypad myKeypad = Keypad(makeKeymap(keys), rowPins, colPins, NUMROWS, NUMCOLS);




Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
                   JOYSTICK_TYPE_JOYSTICK, 25, 0,
                   false, false, false, false, false, false,
                   false, false, false, false, false);



void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Joystick.begin();
}

void loop() {


  if (myKeypad.getKeys())
  {
    for (int i = 0; i < NUMBUTTONS; i++)
    {
      if ( myKeypad.key[i].stateChanged )
      {
        switch (myKeypad.key[i].kstate) {
          case PRESSED:
          case HOLD:
            Joystick.setButton(myKeypad.key[i].kchar, 1);
            Joystick.sendState();
            break;
          case RELEASED:
          case IDLE:
            Joystick.setButton(myKeypad.key[i].kchar, 0);
            Joystick.sendState();
            break;


        }

      }
    }

  }
}