This is a matrix-keypad 12 rows x 4 columns made out of 3 4x4 keypads, the hardware is all working fine. A Sparfun Pro Micro board is been used.
Initially I wrote a code for 12 rows and 4 collumns but that didn't work. I can only make things work with a 10 rows code. This working 10-rows code is shown below:
#include <Keypad.h>
#include <MIDIUSB.h>
const byte ROWS = 10; // number of rows (add 2 more for 12 rows)
const byte COLS = 4; // number of columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'a','b','c','d'},
{'e','f','g','h'},
{'i','j','k','l'},
{'m','n','o','p'},
{'1','2','3','4'},
{'5','6','7','8'},
{'9','0','X','Y'},
{'A','B','C','D'},
{'E','F','G','H'},
{'I','J','K','L'}
// {'M','N','O','P'} : add for two more rows
// {'Q','R','S','T'}
};
byte rowPins[ROWS] = { 6, 7, 8, 9, 10, 16, 14, 15, 2, 3 }; // add pin 4 and 5 for 12 rows
byte colPins[COLS] = { 21, 20, 19, 18 };
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
}
void setup()
{
Serial.begin(115200);
}
void loop(){
char key = keypad.getKey(); //read key
if (key){
Serial.println(key);
noteOn(0, (key), 127);
MidiUSB.flush();
delay(10);
noteOff(0, (key), 127);
MidiUSB.flush();
delay(10);
}
}
With 12 rows code a continuous sort of loop occurs. No way a keypress is detected, instead it prints millions of "Q" (row 12 column 1) .
I guess it has something to do with my code. I'm new to programming Arduino. Any help would be very much appreciated!