Keypad matrix state change problem

Hi, i'm designing a midi controller which involves a button matrix, and since i need to use the pressed and released states from every button, i chose to use the keypad.h library, after using the MultiKey example adapted to my code, it does something like it "adds up" the midi note number as i keep pressing more buttons:
Captura de pantalla 2024-06-08 195458
(Here i pressed button 1, 2 and 3 and leave them pressed as i start pressing the rest, and release all at once)
I was expecting being able to press button 1 and send note 0, button 2 and send note 1 and so on (and being able to do that while i'm pressing other buttons), but it's not happening, am i missing something here?
Code used in this part:

void keyread()
  {
    if(keyb.getKeys()==1)
    {
      for(int i=0; i<LIST_MAX; i++)
      {
        if(keyb.key[i].stateChanged)   // Only find keys that have changed state.
        {
          switch(keyb.key[i].kstate)
          {
            case PRESSED:
              sendnote(i, 127);
              break;
            case IDLE:
              sendnote(i, 0);
              break;
          }
        }
      }
    }
  }

(sendnote(Note, Velocity) involves using 127 as a "NoteON" command to the "i" note number, and 0 as a "NoteOFF" command.)
(the rest of the code is working flawlessly)

Okay, fixed, i was using the counter variable (i) instead of the "keyb.key[i].kchar" function the example provided:

void keyread()
  {
    if(keyb.getKeys()==1)
    {
      for(int i=0; i<LIST_MAX; i++)
      {
        if(keyb.key[i].stateChanged)   // Only find keys that have changed state.
        {
          switch(keyb.key[i].kstate)
          {
            case PRESSED:
              sendnote(keyb.key[i].kchar, 127); //Used "keyb.key[i].kchar" to know what button was pressed
              break;
            case IDLE:
              sendnote(keyb.key[i].kchar, 0);
              break;
          }
        }
      }
    }
  }
1 Like

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