Hello,
I've put midi on a accordion with a arduino mega. I've changed to a teensy 4.1 for the native midi on usb.
Now I have a strange behavior on the keyboard matrix.
I have a 12 row 4 column matrix for the right hand. It worked fine with the Mega.
Now I get a constant midi output. Even if I don't attach any wires. Just a bare Teensy. I changed the pin (11) in the sketch, but the problem consists.
If I remove the last row on pin 11 it works fine. I can use the keyboard. But add the last row the constant output is back. I get the same note. D#
keypad.h has 12 rows as maximum.
I have to work out other issues to, but want to sort this out before wasting time on a broken teensy if that would be the case.
Could sombody give me a hint, I can't find anything.
I've put midi on a accordion with a arduino mega. I've changed to a teensy 4.1 for the native midi on usb.
Now I have a strange behavior on the keyboard matrix.
I have a 12 row 4 column matrix for the right hand. It worked fine with the Mega.
Now I get a constant midi output. Even if I don't attach any wires. Just a bare Teensy. I changed the pin (11) in the sketch, but the problem consists.
If I remove the last row on pin 11 it works fine. I can use the keyboard. But add the last row the constant output is back. I get the same note. D#
keypad.h has 12 rows as maximum.
I have to work out other issues to, but want to sort this out before wasting time on a broken teensy if that would be the case.
Could sombody give me a hint, I can't find anything.
Code:
#include <Keypad.h>
static const bool UseRunningStatus = false;
int val = 0;
int lastVal = 0;
unsigned long time_to_Measure = 0;
const int Measure_Period = 2000; // Update measurement every 2000 msec.
//MIDI_CREATE_DEFAULT_INSTANCE();
const byte ROWS = 11;
const byte COLS = 4;
//define the cymbols on the buttons of the keypads
char keys[ROWS][COLS] = {
{0,76,88,100},//E 22
{65,77,89,101},//F 23
{66,78,90,102},//F# 24
{67,79,91,103},//G 25
{68,80,92,104},//G# 26
{69,81,93,105},//A 27
{70,82,94,0},//A# 28
{71,83,95,0},//B 31
{72,84,96,0},//C 29
{73,85,97,0},//C# 30
{74,86,98,0}//,//D 32
{75,87,99,0}//D# 33
};
byte rowPins[ROWS] = {0,1,2,3,4,5,6,7,8,9,10,11}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {26,25,24,12}; //connect to the column pinouts of the keypad
const byte ROWSBAS = 6;
const byte COLSBAS = 4;
char keys2[ROWSBAS][COLSBAS] = {
{38,44}, //D,G#
{37,39}, //C#,D#
{42,46}, //F#,A#
{47,41}, //B,F
{40,36}, //E,C
{45,43} //A,G
};
byte rowPins2[ROWSBAS] = {27,28,29,30,31,32}; //connect to the row pinouts of the keypad
byte colPins2[COLSBAS] = {34,33}; //connect to the column pinouts of the keypad
const byte ROWSBASAK = 6;
const byte COLSBASAK = 2;
char keysAK[ROWSBASAK][COLSBASAK] = {
{45,39}, //A,D#,
{44,38}, //G#,D,
{43,37}, //G,C#,
{42,36}, //F#,C,
{41,47}, //F,B,
{40,46} //E,A#,
};
byte rowPinsAK[ROWSBASAK] = {27,28,29,30,31,32}; //connect to the row pinouts of the keypad
byte colPinsAK[COLSBASAK] = {36,35}; //connect to the column pinouts of the keypad
// registerdeel
const byte ROWSREG = 7;
const byte COLSREG = 2;
char keys3[ROWSREG][COLSREG] = {
{48,54},
{49},
{50},
{51},
{52},
{53}
//{54}
};
byte rowPins3[ROWSREG] = {13,37,38,39,40,41};
byte colPins3[COLSREG] = {14,15};
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
Keypad kpd2 = Keypad( makeKeymap(keys2), rowPins2, colPins2, ROWSBAS, COLSBAS);
Keypad kpd3 = Keypad( makeKeymap(keys3), rowPins3, colPins3, ROWSREG, COLSREG);
Keypad kpdAK = Keypad( makeKeymap(keysAK), rowPinsAK, colPinsAK, ROWSBASAK, COLSBASAK);
String msg; //for debugging
// master volume part //
byte analogPin = A2;
void setup() {
kpd.setDebounceTime(100); //debounce 50 miliceconde
//kpd2.setDebounceTime(50); //debounce 50 miliceconde
//kpdAK.setDebounceTime(50); //debounce 50 miliceconde
//kpd.setHoldTime(50);
}
void loop() {
volumepod();
diskant();
baskant();
regdiskant();
}
// volume
void volumepod(){
if ((millis() - time_to_Measure) > Measure_Period) {
val = analogRead(A2)/8; // Divide by 8 to get range of 0-127 for midi
if (val != lastVal) // If the value does not = the last value the following command is made. This is because the pot has been turned. Otherwise the pot remains the same and no midi message is output.
{
usbMIDI.sendControlChange(7, val, 1);
usbMIDI.sendControlChange(7, val, 2);
usbMIDI.sendControlChange(7, val, 3);
usbMIDI.sendControlChange(7, val, 4);
usbMIDI.sendControlChange(7, val, 5);
usbMIDI.sendControlChange(7, val, 6);
usbMIDI.sendControlChange(7, val, 7);
usbMIDI.sendControlChange(7, val, 8);
usbMIDI.sendControlChange(7, val, 9);
usbMIDI.sendControlChange(7, val, 10);
usbMIDI.sendControlChange(7, val, 11);
usbMIDI.sendControlChange(7, val, 12);
usbMIDI.sendControlChange(7, val, 13);
usbMIDI.sendControlChange(7, val, 13);} // cc control nummer (7 volume), waarde, kanaal
lastVal = val;
time_to_Measure = millis();
//delay(10); //here we add a short delay to help prevent slight fluctuations, knocks on the pots etc. Adding this helped to prevent my pots from jumpin up or down a value when slightly touched or knocked.
}
}
// diskant knoppen
void diskant(){
// Fills kpd.key[ ] 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.
{
int midinote = kpd.key[i].kchar; //convert the midi note to int from char
switch (kpd.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
case PRESSED: //this messages are for debugging so they are not necessary.
//msg = " PRESSED.";
usbMIDI.sendNoteOn(midinote, 127, 1); //12 is an octave shift (I developed all the code so C1 was the lowest note. With this, it is C2 instead).
usbMIDI.sendNoteOn(midinote, 127, 4);
usbMIDI.sendNoteOn(midinote, 127, 5);
usbMIDI.sendNoteOn(midinote, 127, 6);
usbMIDI.sendNoteOn(midinote, 127, 7);
usbMIDI.sendNoteOn(midinote, 127, 8);
usbMIDI.sendNoteOn(midinote, 127, 9);
usbMIDI.sendNoteOn(midinote, 127, 10);
usbMIDI.sendNoteOn(midinote, 127, 11);
usbMIDI.sendNoteOn(midinote, 127, 12);
usbMIDI.sendPitchBend(-300,4); //musset midden riet op toon
usbMIDI.sendPitchBend(-1035,5); //Frans musette -18cent
usbMIDI.sendPitchBend(+448,6); //Frans musette +18cent
usbMIDI.sendPitchBend(-820,7); //Italiaans musette -13cent
usbMIDI.sendPitchBend(+245,8); //Italiaans musette +13cent
usbMIDI.sendPitchBend(-770,9); //Bayan musette -12cent
usbMIDI.sendPitchBend(+330,10); //Bayan musette +15cent
usbMIDI.sendPitchBend(-610,11); //Amerikaans musette -8cent
usbMIDI.sendPitchBend(+80,12); //Amerikaans musette +8cent
break;
case RELEASED:
//msg = " RELEASED.";
usbMIDI.sendNoteOff(midinote, 127, 1);
usbMIDI.sendNoteOff(midinote, 127, 4);
usbMIDI.sendNoteOff(midinote, 127, 5);
usbMIDI.sendNoteOff(midinote, 127, 6);
usbMIDI.sendNoteOff(midinote, 127, 7);
usbMIDI.sendNoteOff(midinote, 127, 8);
usbMIDI.sendNoteOff(midinote, 127, 9);
usbMIDI.sendNoteOff(midinote, 127, 10);
usbMIDI.sendNoteOff(midinote, 127, 11);
usbMIDI.sendNoteOff(midinote, 127, 12);
break;
case HOLD:
usbMIDI.sendNoteOn(midinote, 127, 1); //12 is an octave shift (I developed all the code so C1 was the lowest note. With this, it is C2 instead).
usbMIDI.sendNoteOn(midinote, 127, 4);
usbMIDI.sendNoteOn(midinote, 127, 5);
usbMIDI.sendNoteOn(midinote, 127, 6);
usbMIDI.sendNoteOn(midinote, 127, 7);
usbMIDI.sendNoteOn(midinote, 127, 8);
usbMIDI.sendNoteOn(midinote, 127, 9);
usbMIDI.sendNoteOn(midinote, 127, 10);
usbMIDI.sendNoteOn(midinote, 127, 11);
usbMIDI.sendNoteOn(midinote, 127, 12);
usbMIDI.sendPitchBend(-300,4); //musset midden riet op toon
usbMIDI.sendPitchBend(-1035,5); //Frans musette -18cent
usbMIDI.sendPitchBend(+448,6); //Frans musette +18cent
usbMIDI.sendPitchBend(-820,7); //Italiaans musette -13cent
usbMIDI.sendPitchBend(+245,8); //Italiaans musette +13cent
usbMIDI.sendPitchBend(-770,9); //Bayan musette -12cent
usbMIDI.sendPitchBend(+330,10); //Bayan musette +15cent
usbMIDI.sendPitchBend(-610,11); //Amerikaans musette -8cent
usbMIDI.sendPitchBend(+80,12); //Amerikaans musette +8cent
break;
case IDLE:
usbMIDI.sendNoteOff(midinote, 127, 1);
usbMIDI.sendNoteOff(midinote, 127, 4);
usbMIDI.sendNoteOff(midinote, 127, 5);
usbMIDI.sendNoteOff(midinote, 127, 6);
usbMIDI.sendNoteOff(midinote, 127, 7);
usbMIDI.sendNoteOff(midinote, 127, 8);
usbMIDI.sendNoteOff(midinote, 127, 9);
usbMIDI.sendNoteOff(midinote, 127, 10);
usbMIDI.sendNoteOff(midinote, 127, 11);
usbMIDI.sendNoteOff(midinote, 127, 12);
break;
}
}
}
}
}
// einde diskant
// bas knoppen
void baskant (){
if (kpd2.getKeys())
{
for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
if ( kpd2.key[i].stateChanged ) // Only find keys that have changed state.
{
int midinote = kpd2.key[i].kchar; //convert the midi note to int from char
switch (kpd2.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
case PRESSED: //this messages are for debugging so they are not necessary.
//msg = " PRESSED.";
usbMIDI.sendNoteOn(midinote, 127, 2); //(midinote+12, 127, 1)
break;
case RELEASED:
//msg = " RELEASED.";
// usbMIDI.sendControlChange(123,0,2);
usbMIDI.sendNoteOff(midinote, 120, 2);
break;
case HOLD:
usbMIDI.sendNoteOn(midinote, 127, 2);
break;
case IDLE:
//usbMIDI.sendControlChange(123,0,2);
usbMIDI.sendNoteOff(midinote+12, 120, 2);
break;
}
break;
delay(30);
}
}
if (kpdAK.getKeys())
{
for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
if ( kpdAK.key[i].stateChanged ) // Only find keys that have changed state.
{
int midinote = kpdAK.key[i].kchar; //convert the midi note to int from char
switch (kpdAK.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
case PRESSED: //this messages are for debugging so they are not necessary.
//msg = " PRESSED.";
usbMIDI.sendNoteOn(midinote, 127, 3); //(midinote+12, 127, 1)
// usbMIDI.sendNoteOn(midinote+12, 120, 2);
break;
case RELEASED:
//msg = " RELEASED.";
// usbMIDI.sendControlChange(123,0,3);
usbMIDI.sendNoteOff(midinote+12, 120, 2);//(midinote+12, 127, 1)
break;
case HOLD:
usbMIDI.sendNoteOn(midinote, 127, 3);
break;
case IDLE:
//usbMIDI.sendControlChange(123,0,3);
usbMIDI.sendNoteOff(midinote+12, 120, 2);
break;
}
break;
delay(30);
}
}
}
// einde bas
// disregister
void regdiskant(){
if (kpd3.getKeys())
{
for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
{
if ( kpd3.key[i].stateChanged ) // Only find keys that have changed state.
{
int midinote = kpd3.key[i].kchar; //convert the midi note to int from char
switch (kpd3.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
case PRESSED: //this messages are for debugging so they are not necessary.
//msg = " PRESSED.";
usbMIDI.sendNoteOn(midinote, 127, 1);
usbMIDI.sendNoteOn(midinote, 127, 4);
usbMIDI.sendNoteOn(midinote, 127, 5);
usbMIDI.sendNoteOn(midinote, 127, 6);
usbMIDI.sendNoteOn(midinote, 127, 8);
usbMIDI.sendNoteOn(midinote, 127, 9);
usbMIDI.sendNoteOn(midinote, 127, 10);
usbMIDI.sendNoteOn(midinote, 127, 11);
usbMIDI.sendNoteOn(midinote, 127, 12);
break;
case RELEASED:
//msg = " RELEASED.";
usbMIDI.sendNoteOff(midinote, 127, 1); //(midinote+12, 127, 1)
usbMIDI.sendNoteOff(midinote, 127, 4);
usbMIDI.sendNoteOff(midinote, 127, 5);
usbMIDI.sendNoteOff(midinote, 127, 6);
usbMIDI.sendNoteOff(midinote, 127, 7);
usbMIDI.sendNoteOff(midinote, 127, 8);
usbMIDI.sendNoteOff(midinote, 127, 9);
usbMIDI.sendNoteOff(midinote, 127, 10);
usbMIDI.sendNoteOff(midinote, 127, 11);
usbMIDI.sendNoteOff(midinote, 127, 12);
break;
case HOLD:
usbMIDI.sendNoteOn(midinote, 127, 1);
usbMIDI.sendNoteOn(midinote, 127, 4);
usbMIDI.sendNoteOn(midinote, 127, 5);
usbMIDI.sendNoteOn(midinote, 127, 6);
usbMIDI.sendNoteOn(midinote, 127, 8);
usbMIDI.sendNoteOn(midinote, 127, 9);
usbMIDI.sendNoteOn(midinote, 127, 10);
usbMIDI.sendNoteOn(midinote, 127, 11);
usbMIDI.sendNoteOn(midinote, 127, 12);
break;
case IDLE:
usbMIDI.sendNoteOff(midinote, 127, 1); //(midinote+12, 127, 1)
usbMIDI.sendNoteOff(midinote, 127, 4);
usbMIDI.sendNoteOff(midinote, 127, 5);
usbMIDI.sendNoteOff(midinote, 127, 6);
usbMIDI.sendNoteOff(midinote, 127, 7);
usbMIDI.sendNoteOff(midinote, 127, 8);
usbMIDI.sendNoteOff(midinote, 127, 9);
usbMIDI.sendNoteOff(midinote, 127, 10);
usbMIDI.sendNoteOff(midinote, 127, 11);
usbMIDI.sendNoteOff(midinote, 127, 12);
break;
}
}
}
}
}
//einde disregister