             }*/
           if ((i + 12 * j) % 2 == 0) {
             if (keyState[i + 12 * j + 1] == 1) {
-              midiSend(noteOn, keyMidi[i + 12 * j], getVelocity((i + 12 * j) / 2));
+              noteOn(keyboardChannel, keyMidi[i + 12 * j], getVelocity((i + 12 * j) / 2));
             } else {
               updateVelocity((i + 12 * j) / 2, (byte)1);
             }
           } else {
             if (keyState[i + 12 * j - 1] == 1) {
-              midiSend(noteOn, keyMidi[i + 12 * j], getVelocity((i + 12 * j) / 2));
+              noteOn(keyboardChannel, keyMidi[i + 12 * j], getVelocity((i + 12 * j) / 2));
             }
             else {
               updateVelocity((i + 12 * j) / 2, (byte)1);

static const byte outClkPin = 12;
static const byte latchPin = 10;
//If a Analog mux is added, just connect the control pins in parallel and add the En pin to the list.
static const byte muxEn [] = {5 };

//Constants
byte mask[] = { B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000 };//To read the columns values
byte blank = B00000000;//To send blank to the register.
byte noteOn = B10010000;
byte noteOff = B10000000;
byte pitchBend = B11100001;
static const short sensitivity = 1000;
static bool debug = false;
static const byte  keyMidiCons[144] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

  }
}

/**
    Method to send a control message with analog values.
    @param pChannel the channel to send the message.
    @param pControl the note to turn on.
    @param pValue the value to send.
*/
void controlMessage(byte pChannel, byte pControl, byte pValue){
  pChannel += control-1;
  midiSend(pChannel,pControl, pValue);
}

/**
    Method to send a note on message.  
    @param pChannel the channel to send the noteon.
    @param pPitch the note to turn on.
    @param pVelocity the velocity of the note.
 */
void noteOn(byte pChannel, byte pPitch, byte pVelocity){
  pChannel += noteON-1;
  midiSend(pChannel, pPitch, pVelocity);
}

/**
    Method to send a note off message.
    @param pChannel the channel to send the noteoff.
    @param pPitch the note to turn off.
 */
void noteOff(byte pChannel, byte pPitch){
  pChannel += noteOFF-1;
  midiSend(pChannel, pPitch, 0);
}

/**
   Method to send the midi message.
   @param statusByte the status midi command.
   @param dataByte1 the first data byte.
   @param dataByte2 the second data byte.
   @return void
*/
void midiSend(byte statusByte, byte dataByte1, byte dataByte2) {
  if (!debug) {
    Serial.write(statusByte);
    Serial.write(dataByte1);
    Serial.write(dataByte2);
  } else {
    Serial.println("Begin Message.");
    Serial.println(statusByte, BIN);
    Serial.println(dataByte1, BIN);
    Serial.println(dataByte2, BIN);
    Serial.println("End Message.");
  }
}
