Editing a Library

Hi euphoricnoise, sorry about the late reply but I am just getting over the flu.

euphoricnoise:
-I am trying to build a 16 buttonpad MIDI controller using the sparkfun 4x4 board (Button Pad 4x4 - LED Compatible - COM-07835 - SparkFun Electronics)
-Right now, the controller can take in one button input and output one thing (monophonic)
-I am trying to program the arduino so more than one button input can be taken in (polyphonic)

The latest version, 3.0, of the keypad library supports up to 10 active keys all being pressed at the same time. I wanted to give you an example but I see that I botched the upload so the multikey example included with the library download is completely off the mark.

I've included my initial draft of that example here. Two things to notice are that you should use kpd.getKeys() for scanning multiple key presses and that you will get a list of keys in the kpd.key[] array.

The array kpd.key[] is an array containing keys that have the following members:

  char kchar;
  KeyState kstate;            // IDLE, PRESSED, HOLD, RELEASED
  boolean stateChanged;

Hopefully this is enough to get you going on your project. I will work on the multikey example over the holidays and see if I can update the Keypad page Arduino Playground - Keypad Library too.

/* @file MultiKey.ino

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the kpd

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
}

void loop(){

  // Fills kpd.key[] array with up-to 10 active keys.
  // Returns true if there are ANY active keys.
  if (kpd.getKeys())
  {
    for (int i=0; i<LIST_MAX; i++)   // Scan the entire list.
    {
      if (kpd.key[i].kchar != NO_KEY)    // Test for an active key.
      {
        switch (kpd.key[i].kstate) {  // Test for key state IDLE, PRESSED, HOLD, or RELEASED
            case HOLD:
                Serial.print("Key ");
                Serial.print(kpd.key[i].kchar);
                Serial.print(" is being HELD and the state ");
                if (!kpd.key[i].stateChanged)
                    Serial.println("has not changed.");
                else
                    Serial.println("has changed.");
                break;
            case PRESSED:
                Serial.print("Key ");
                Serial.print(kpd.key[i].kchar);
                Serial.print(" is PRESSED and the state ");
                if (!kpd.key[i].stateChanged)
                    Serial.println("has not changed.");
                else
                    Serial.println("has changed.");
                break;
            case RELEASED:
                Serial.print("Key ");
                Serial.print(kpd.key[i].kchar);
                Serial.print(" has been RELEASED and the state ");
                if (!kpd.key[i].stateChanged)
                    Serial.println("has not changed.");
                else
                    Serial.println("has changed.");
                break;
            default:
                Serial.print("Key ");
                Serial.print(kpd.key[i].kchar);
                Serial.print(" is IDLE and the state ");
                if (!kpd.key[i].stateChanged)
                    Serial.println("has not changed.");
                else
                    Serial.println("has changed.");
        }
      }
    }
  }
}  // End loop