Hello fellow programmers/hobbyists..
Im reusing a old cassio 61-key keyboard to plug on my DAW (LPX).
I did sucecefully flashed the arduino_mega and played a bit with the daw.
But im facing a few problems. Will try to explain best i can:
If I use it as 60-key matrix everything work's great, only downsize is that key-61 does not work (i can live with that for now, but want things to go as per OEM possible)
The working code I've used is this:
#include <MIDI.h>
#include <Keypad.h>
const byte ROWS = 10; // 6 Linhas
const byte COLS = 6; // 11 Colunas
char keys[ROWS][COLS] = {
{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, 97, 98, 99, 100, 101},
{102, 103, 104, 105, 106, 107}
};
byte rowPins[ROWS] = {22, 24, 26, 28, 30, 32, 34, 36, 38, 40}; //conectar-se às pinagens de linha do teclado
byte colPins[COLS] = {A0, A1, A2, A3, A4, A5}; //conectar-se às pinagens das colunas do teclado
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
byte pressed = 32;
byte chanel = 0; // Canal MIDI para usar
void setup() {
Serial.begin(115200); // definir isso o mesmo que no Hairless
}
void loop() {
// Fills kpd.key[49] array with up-to 10 active keys.
// Returns true if there are ANY active keys.
if (kpd.getKeys())
{
for (int i = 0; i < LIST_MAX; i++) // Scan the whole key list.
{
if ( kpd.key[i].stateChanged ) // Only find keys that have changed state.
{
pressed = kpd.key[i].kchar;// + 12;
switch (kpd.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
case PRESSED:
sendMIDI(chanel | 0x90, pressed, 100);
break;
case RELEASED:
sendMIDI(chanel | 0x80, pressed, 64);
break;
}
}
}
}
} // End loop
void sendMIDI(byte type, byte note, byte velocity){
Serial.write(type);
Serial.write(note & 0x7F);
Serial.write(velocity);
}
Now when I try edit this code to work with the extra row it goes wild. Not only it does not detect the C7 key and also every time i press another key I do not get a note_off and get 3 or 4 ghost keys.
For the sake of it I test this key matrix plugged as C3 (key 60) and works fine, so hardware is not the cause.
Next I went editing and updating the code to find what part is messing everything up.
As soon as I edit this bit, I start getting weird results. In this case pin_42 (I did test with bunch of other pins same result)
byte rowPins[ROWS] = {22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42}; //conectar-se às pinagens de linha do teclado
also I did change the matrix to include with no working results, same bug :
{108, 0, 0, 0, 0, 0}
From test I found that the part that letting me put the row pins goes wild when I set an 11'th pin row of the matrix.
Have someone a ideia how to approach it? Hardware wise its ok because artifacts appear as soon I press a key and not only when I press keys that are matrix linked with the problematic one, so it can only be code issue.
Can someone give a newbie a hand? Or brain
ctk500.pdf (1.54 MB)