I am trying to program my Arduino Mega to work as a Midi controller.
For Background, I have a digital Allen 225 RTC organ, that is in good working condition, but I wanted to add Midi. It has a 6x11 matrix encoding each keyboard (there are 2) and the pedalboard. With test sketches, I have figured out that the Allen pulls the columns low 4 times in 40 microseconds, then waits about 600 microseconds, then pulls the columns low again. If the key is pressed down when the column goes low, then the row goes low at the same time.
I will work on a schematic, but what I did is wire one pin of an Arduino Mega to each row or column of each keyboard and pedal. That means, there is a direct electrical connection from the keyboard row to the Arduino "row" pin, and from the keyboard column to the Arduino "column" pin.
In the below code, Pin2 is soldered to the wire from the first row of keyboard A, and Pin32 is soldered to the first column of keyboard A.
I have run some test sketches, which is how I know roughly how long between and how many times the Allen columns go low.
I have gotten it to work so that keys are recognized as on or off, and the appropriate midi message is sent, however I continuously get on/off/on/off... messages when I hold down the key (that stop when I let go of the key).
I have tried all manner of different ways of programming it, and I can't come up with what I am doing wrong.
The Allen circuits are undocumented, but they seem to be readable when you run a test sketch.
Any help would be appreciated!
// Name: Arduino Mega Midi Controller v16
// Created: Dec 23, 2020.
// Author: Larason2
byte Pin2;
byte Pin32;
byte lastA[11][6];
byte lastB[11][6];
byte lastC[7][6];
const int noteOn1 = 144;
const int noteOff1 = 128;
const int velocity = 100;
void setup() {
// Start Serial
Serial.begin(31250);
pinMode(2, INPUT);
pinMode(32, INPUT);
}
void loop() {
pinMode(2, INPUT_PULLUP);
Pin2 = digitalRead(2);
pinMode(2, INPUT);
pinMode(32, INPUT_PULLUP);
Pin32 = digitalRead(32);
pinMode(32, INPUT);
if((Pin32 == 0) and (Pin2 == 0) and (lastA[0][0] == 0)) {
MidiSend(noteOn1, 36, velocity);
lastA[0][0] = 1;
}
if((Pin32 == 0) and (Pin2 == 1) and (lastA[0][0] == 1)) {
MidiSend(noteOff1, 36, velocity);
lastA[0][0] = 0;
}
}
void MidiSend(int cmd, int note, int vel) {
Serial.write(cmd);
Serial.write(note);
Serial.write(vel);
}