hi there i have a key matrix setup for a midi foot controller i am working on. it consists of 56 buttons (keys) arranged in a 8x7 matrix.
this is my test code:
it mostly works. some keys behave strangely though. they report as different keys. first i thought it was a wiring problem, but resoldering did not help. also i realised that since i get a key reported (the false one) the wires have to be connected somehow "right" since with only one or no wire attached there was of course no reading for this switch. i am pretty confident the code is alright, since it works for almost all switches.
things i noticed:
when i put my finger across the switch contacts and "short" them with my finger i sometimes get the correct readings on the non working switches. so i thought, aha bad soldering, but no, that is not it.
so, might it be that my cables are too long for the teensy digital pins? since this is a large foot controller they span for about 1,5m to 2m for some connections. the thing with the finger led me to believe it could be something like that, just gut feeling.
also noteworthy: there are quite some keys that start to report false keys when i put a finger across the switch terminals, they all work correctly when they are not touched though.
or could a bouncy switch be the cause? the faulty switches report either as switch from the same position a row above or as the switch before in that column, so i.e. the key that should read "E" outputs "D".
can there be done something about the cable length thing? external pull up resistors? or is the teensy 4.0 to fast for the key matrix to work correctly, do i need to slow the reading part down?
thanks for any tips!
this is my test code:
Code:
/* @file EventSerialKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates using the KeypadEvent.
|| #
*/
#include <Keypad.h>
const byte ROWS = 8; //four rows
const byte COLS = 7; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','4','5','6','7'},
{'8','9','A','B','C','D','E'},
{'F','G','H','I','J','K','L'},
{'M','N','O','P','Q','R','S'},
{'T','U','V','W','X','Y','Z'},
{'a','b','c','d','e','f','g'},
{'h','i','j','k','l','m','n'},
{'o','p','q','r','s','t','u'},
};
byte rowPins[ROWS] = {2, 3, 4, 5, 6, 9, 10, 11}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {27, 29, 31, 33, 28, 30, 12 }; //connect to the column pinouts of the kpd
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
byte ledPin = 13;
boolean blink = false;
boolean ledPin_state;
void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // Sets the digital pin as output.
digitalWrite(ledPin, HIGH); // Turn the LED on.
ledPin_state = digitalRead(ledPin); // Store initial LED state. HIGH when LED is on.
keypad.addEventListener(keypadEvent); // Add an event listener for this keypad
}
void loop(){
char key = keypad.getKey();
if (key) {
Serial.println(key);
}
/* if (blink){
digitalWrite(ledPin,!digitalRead(ledPin)); // Change the ledPin from Hi2Lo or Lo2Hi.
delay(100);
} */
}
// Taking care of some special events.
void keypadEvent(KeypadEvent key){
switch (keypad.getState()){
case PRESSED:
if (key == 't') {
digitalWrite(ledPin,!digitalRead(ledPin));
ledPin_state = digitalRead(ledPin); // Remember LED state, lit or unlit.
}
break;
case RELEASED:
if (key == 't') {
digitalWrite(ledPin,ledPin_state); // Restore LED state from before it started blinking.
blink = false;
}
break;
case HOLD:
if (key == 's') {
blink = true; // Blink the LED when holding the * key.
}
break;
}
}
it mostly works. some keys behave strangely though. they report as different keys. first i thought it was a wiring problem, but resoldering did not help. also i realised that since i get a key reported (the false one) the wires have to be connected somehow "right" since with only one or no wire attached there was of course no reading for this switch. i am pretty confident the code is alright, since it works for almost all switches.
things i noticed:
when i put my finger across the switch contacts and "short" them with my finger i sometimes get the correct readings on the non working switches. so i thought, aha bad soldering, but no, that is not it.
so, might it be that my cables are too long for the teensy digital pins? since this is a large foot controller they span for about 1,5m to 2m for some connections. the thing with the finger led me to believe it could be something like that, just gut feeling.
also noteworthy: there are quite some keys that start to report false keys when i put a finger across the switch terminals, they all work correctly when they are not touched though.
or could a bouncy switch be the cause? the faulty switches report either as switch from the same position a row above or as the switch before in that column, so i.e. the key that should read "E" outputs "D".
can there be done something about the cable length thing? external pull up resistors? or is the teensy 4.0 to fast for the key matrix to work correctly, do i need to slow the reading part down?
thanks for any tips!