Hello,
I'm trying to build a keyboard using a Teensy 4.1. I've tried running a few different firmwares I found online but had a problem where the keyboard would output both the key pressed and the key on the row beneath.
There's no obvious shorts/problems in the hardware side of things, so I wanted to check if the problem was in the code I was running. I wrote some short code to print out if a key on a specific row was pressed, with the plan to check each key press outputs the intended row/column pins. In the Arduino IDE, board is set to Teensy 4.1, USB type is "Keyboard".
//Define number of rows and columns in keyboard
const int NUM_ROWS = 6;
const int NUM_COLS = 22;
//Define pin numbers of rows and columns
int rowPins[] = {38,37,36,35,34,33};
int colPins[] = {3,4,5,6,7,8,9,10,11,12,13,14,40,24,25,26,27,28,29,30,31,32};
//test row 1 switches
int R1 = 38;
void setup() {
Keyboard.begin();
//test pin 38
pinMode(R1,INPUT_PULLUP);
if (digitalRead(R1)) {
Keyboard.write("pin 38 high");
} else{
Keyboard.write("pin 38 low");
}
//this part does not print anything
}
void loop() {
if (digitalRead(R1)) {
Keyboard.write("Key on row 1 not pressed"); //does print
delay(5000);
} else {
Keyboard.write("Key on row 1 pressed"); //never prints
}
}
I've tried this to check a few rows and columns but it never outputs that a key is pressed. I know the switches are wired at least mostly correctly, as the keyboard will type something with a different firmware.
I am getting some funny voltage readings from the pins, but that's likely because it's difficult to hold the multimeter whilst not pressing any keys.
I'm also still learning C, so perhaps (hopefully) the problem is glaringly obvious.
Any help would be greatly appreciated.
