I have written this code for my 6 octave 72 key piano, however the octaves above 2 are fine, if I press a key on the 1st of 2nd octave, it will trigger the same key from the first and 2nd row when only one is pressed.. and I cant for the love of me see where its going wrong in the code.
I had this working perfectly and lost my code so had to re-write it
A wiring explanation of the physical keyboard circuit is as follows.
Octave 1: Has 9 Keys and starts on key 16
Octave 2: has 12 Keys and starts on key 25
Octave 3: has 12 Keys and starts on key 37
Octave 4: has 12 Keys and starts on key 49
Octave 5: has 12 Keys and starts on key 61
Octave 6: has 12 Keys and starts on key 84
If I press Key 18 on Octave 1, it will MIDI output the same key, on octave 1 & 2. Anything above octave 2 doesn't bug out like this
I have attached the snippet
#include <MIDI.h>
#include <Keypad.h>
int quiet = 0;
const byte ROWS = 6; //Seven rows
const byte COLS = 12; //Ten columns
char keys[ROWS][COLS] = {
{13,14,15,16,17,18,19,20,21,22,23,24},
{25,26,27,28,29,30,31,32,33,34,35,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}
};
byte rowPins[ROWS] = {A0,A1,A2,A3,A4,A5}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {8,2,9,3,10,4,11,5,12,6,13,7}; //connect to the column pinouts of the kpd
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
Serial.begin(115200);
}
void loop() {
if (kpd.getKeys())
{
for (int i=0; i<72; i++) // Scan the whole key list.
{
if ((kpd.key[i].stateChanged ) && (kpd.key[i].kstate == PRESSED)) // Only find keys that have changed state.
{
int myKey = (kpd.key[i].kchar);
{
Serial.write(144);
Serial.write(myKey);
Serial.write(100);
}
}
if ((kpd.key[i].stateChanged ) && (kpd.key[i].kstate == RELEASED)) // Only find keys that have changed state.
{
int myKey = (kpd.key[i].kchar);
{
Serial.write(128);
Serial.write(myKey);
Serial.write(quiet);
}
}
}
}
}