Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

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

  1. #1
    Junior Member
    Join Date
    Aug 2018
    Posts
    4

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

    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.

    Click image for larger version. 

Name:	teensy_in.thumb.jpg 
Views:	3 
Size:	150.4 KB 
ID:	18382
    Click image for larger version. 

Name:	up_close_teensy.thumb.jpg 
Views:	2 
Size:	108.7 KB 
ID:	18381.

  2. #2
    I googled ‘Arduino key matrix example’ , and the top hit was an article which explains it clearly:
    https://www.baldengineer.com/arduino...-tutorial.html

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,085

  4. #4
    Junior Member
    Join Date
    Aug 2018
    Posts
    4

    It only works Serial Monitor

    Quote Originally Posted by PaulStoffregen View Post
    I've programmed the keypad and I can send keystrokes because they register on the serial monitor, but the keystrokes don't register in any programs. What code do I use to have the keypad input register in a program other than the serial monitor?

  5. #5
    Can you be specific? What program ran and displayed on serial monitor? What program didn’t work?

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,085
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •