 // constants won't change. They're used here to
 // set pin numbers for first 2 octaves
 const int keyPins[] = {28, 26, 24, 22, 13, 12, 11, 10, 9, 8, 7, 6, 14, 15, 16, 17, 18, 19, 20, 21, 27, 25, 23, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30,};
-const int rankPins[] = {5, }; // drive wire(s) for ranks
+const int rankPins[] = {5, 4, }; // drive wire(s) for ranks are: {5, 4, 3, 2, 67, and 69 (pedals)}
+const int pedalPin = 69;
 /*
   Note for reference, the analog -> digital pin mappings for the Mega are:
   A0 = 54



// function to handle the loop over a given rank, updating states
void rankPoll(const int keyPins[], bool (&states)[], int arraySize, int rank) {
  for(int key=0; key<arraySize; key++){
      // run through all switches, reading their values
      // pass results to keyChange which will dispatch a MIDI event if needed
      keyChange(digitalRead(keyPins[key]), states[key], key, midiChannels[rank]);
  }
}


// define how large some things are (matrix size)
const int numKeys = 61;    // full organ manual, also length of keyPins and midiKeyNotes
const int numPedals = 32;  // full AGO 32-key pedalboard
const int numManuals = 2;  // number of manuals

const unsigned char midiKeyNotes[numKeys] = {36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, };
const unsigned char midiChannels[numManuals] = {1, 2, };  // Five manuals plus pedals (pedals always rank 16)
const unsigned char pedalChannel = 16;

// State of all keys in a 2D multidimensional array
bool keyStates[numManuals][numKeys] = {
  {no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, },
  {no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, },
};

// State of all pedals in a 1D array
bool pedalStates[numPedals] = {no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, };


// Convenience func to convert a boolean to the proper MIDI key velocity
