just connected the remaining wires of the matrix
#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>
#define NUM_ROWS 16
#define NUM_COLS 16
#define NOTE_ON_CMD 0x90
#define NOTE_OFF_CMD 0x80
#define NOTE_VELOCITY 127
#define SERIAL_RATE 19200
const int row1Pin = 3;
const int row2Pin = 4;
const int row3Pin = 5;
const int row4Pin = 6;
const int row5Pin = 7;
const int row6Pin = 8;
const int row7Pin = 9;
const int row8Pin = 10;
const int row9Pin = A0;
const int row10Pin = A1;
const int row11Pin = A2;
const int row12Pin = A3;
const int row13Pin = A4;
const int row14Pin = A5;
const int row15Pin = 2;
const int row16Pin = 0;
const int dataPin = 11;
const int latchPin = 12;
const int clockPin = 13;
boolean keyPressed[NUM_ROWS][NUM_COLS];
uint8_t keyToMidiMap[NUM_ROWS][NUM_COLS] = { //8X
36, 37, 38, 39, 40, 41, 42, 43,
11, 11, 11, 11, 11, 11, 11, 11,
44, 45, 46, 47, 48, 49, 50, 51,
11, 11, 11, 11, 11, 11, 11, 11,
52, 53, 54, 55, 56, 57, 58, 59,
11, 11, 11, 11, 11, 11, 11, 11,
60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 13, 11, 11, 11, //8
11, 11, 11, 11, 11, 11, 11, 11,
68, 69, 70, 71, 72, 73, 74, 75,
16, 11, 11, 11, 16, 11, 11, 11,
76, 77, 78, 79, 80, 81, 82, 83,
18, 11, 11, 11, 11, 11, 11, 11,
84, 85, 86, 87, 88, 89, 90, 91,
11, 11, 11, 11, 11, 11, 11, 11,
92, 93, 94, 95, 96, //16
};
int bits[] =
{
B11111110,
B11111101,
B11111011,
B11110111,
B11101111,
B11011111,
B10111111,
B01111111
};
void setup()
{
int note = 64;
for(int colCtr = 0; colCtr < NUM_COLS; ++colCtr)
{
for(int rowCtr = 0; rowCtr < NUM_ROWS; ++rowCtr)
{
keyPressed[rowCtr][colCtr] = false;
note++;
}
}
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(row1Pin, INPUT);
pinMode(row2Pin, INPUT);
pinMode(row3Pin, INPUT);
pinMode(row4Pin, INPUT);
pinMode(row5Pin, INPUT);
pinMode(row6Pin, INPUT);
pinMode(row7Pin, INPUT);
pinMode(row8Pin, INPUT);
pinMode(row9Pin, INPUT);
pinMode(row10Pin, INPUT);
pinMode(row11Pin, INPUT);
pinMode(row12Pin, INPUT);
pinMode(row13Pin, INPUT);
pinMode(row14Pin, INPUT);
pinMode(row13Pin, INPUT);
pinMode(row14Pin, INPUT);
Serial.begin(SERIAL_RATE);
}
void loop()
{
for (int colCtr = 0; colCtr < NUM_COLS; ++colCtr)
{
scanColumn(colCtr);
int rowValue[NUM_ROWS];
rowValue[0] = !digitalRead(row1Pin);
rowValue[1] = !digitalRead(row2Pin);
rowValue[2] = !digitalRead(row3Pin);
rowValue[3] = !digitalRead(row4Pin);
rowValue[4] = !digitalRead(row5Pin);
rowValue[5] = !digitalRead(row6Pin);
rowValue[6] = !digitalRead(row7Pin);
rowValue[7] = !digitalRead(row8Pin);
rowValue[8] = !digitalRead(row9Pin);
rowValue[9] = !digitalRead(row10Pin);
rowValue[10] = !digitalRead(row11Pin);
rowValue[11] = !digitalRead(row12Pin);
rowValue[12] = !digitalRead(row13Pin);
rowValue[13] = !digitalRead(row14Pin);
rowValue[14] = !digitalRead(row15Pin);
rowValue[15] = !digitalRead(row16Pin);
for(int rowCtr=0; rowCtr<NUM_ROWS; ++rowCtr)
{
if(rowValue[rowCtr] != 0 && !keyPressed[rowCtr][colCtr])
{
keyPressed[rowCtr][colCtr] = true;
noteOn(rowCtr,colCtr);
}
}
// process keys released
for(int rowCtr=0; rowCtr<NUM_ROWS; ++rowCtr)
{
if(rowValue[rowCtr] == 0 && keyPressed[rowCtr][colCtr])
{
keyPressed[rowCtr][colCtr] = false;
noteOff(rowCtr,colCtr);
}
}
}
}
void scanColumn(int colNum)
{
digitalWrite(latchPin, LOW);
if(0 <= colNum && colNum <= 7)
{
shiftOut(dataPin, clockPin, MSBFIRST, B11111111); //right sr
shiftOut(dataPin, clockPin, MSBFIRST, bits[colNum]); //left sr
}
else
{
shiftOut(dataPin, clockPin, MSBFIRST, bits[colNum-8]); //right sr
shiftOut(dataPin, clockPin, MSBFIRST, B11111111); //left sr
}
digitalWrite(latchPin, HIGH);
}
void noteOn(int row, int col)
{
Serial.write(NOTE_ON_CMD);
Serial.write(keyToMidiMap[row][col]);
Serial.write(NOTE_VELOCITY);
}
void noteOff(int row, int col)
{
Serial.write(NOTE_OFF_CMD);
Serial.write(keyToMidiMap[row][col]);
Serial.write(NOTE_VELOCITY);
}
haven't arranged them on the array yet, so they show as note 0, velocity 127. I need to show as velocity 60 or something like that, heeeelp is the last thing and can solder and finish this.