How do I code a keyboard when keys are in rows and columns wired from pin to pin?

Status
Not open for further replies.

brbeaton

New member
I have been making custom keyboards that only have 24 or fewer keys because the Teensy 2.0 only has 24 pins. I've come to the point where I want to create a keyboard that has a greater number of keys, so I surfed schematics and they have shown me that I have to connect keys in columns and rows. The columns are connected to pins 0 through 10 and the rows are connected to pins 11-21 (with some pins not used on either side). For example, a wire runs from pin 9 through the ALT, Z, A, Q and 1 keys, and each of these keys returns the signal to the Teensy board through connections to pins 12, 13, 14, 15 and 16 respectively. If I press the "Q" key, a circuit is completed from pin 9 to pin 15.

The code that I used to run when my keys were connected directly from pin to ground no longer works for this new configuration. I've wired up a single key, in this case from pin 9 to pin 15, and I want to know how I code the Teensy 2.0 board to recognize it. I've included some generic pictures of how keyboards are wired using Teensy 2.0 so people can see how keys are wired and connected to the board.

Here is a single key example of the code I used to use:

#include <Bounce.h>
Bounce button0 = Bounce(0, 3);
void setup() {
pinMode(0, INPUT_PULLUP);
}
void loop() {
button0.update();
if (button0.fallingEdge()) {
Keyboard.press(KEY_0);
Keyboard.release(KEY_0);
}
}

How do I code this new method of wiring the board? If I could code just 1 key I'd figure out how to do the rest.

teensy_in.thumb.jpg
up_close_teensy.thumb.jpg.
 
Well of course the Keypad library examples only send to the serial monitor. They use Serial.print().

You need to copy and paste code, maybe even improvise slightly, to create a hybrid of these 2 examples which accomplishes your goals. That's what these examples are all about. They're meant to be building blocks that you can put together to make a program to suit your own needs.

You can do this. Try copying those Keyboard.press() and Keyboard.release() lines into the Keypad example. You might need to modify the code somewhat. Look at the other examples to see how things are done. If you get stuck, we can try to help... but you must show us the complete program you've tried. We can probably help you if you get stuck, but *you* have to take the initiative to cobble together a program from multiple examples that does what you want.
 
Status
Not open for further replies.
Back
Top