I want to make keyboard with 4x4 keypad in Pro Micro

Hello guys. I want to make a macro keyboard with a 4x4 Keypad. I can do this with a single button, but I could not code it as a 4x4 keyboard.

Since I want to control approximately 32 buttons, I will use a 4x4 keypad. If I use a single button, the pins on the pro micro will not be enough.

I am sharing sample code for single button. This code works as I want for single button. Can you help me with the coding to make a 4x4 version of this? :slight_smile:


#include <Keyboard.h>

bool isPressing1 = false;

void setup() {
  pinMode(2, INPUT_PULLUP);

  // Setup Serial Monitor
  Serial.begin (9600);
  //Consumer.begin();
  Keyboard.begin();
 
}
  void loop() {
  if (digitalRead(2) == LOW) {
    
    if (isPressing1){
       //do nothing       
    }
    else{
      isPressing1 = true;
      Keyboard.press('d');
    }
  }
  else {
     if (isPressing1){
      isPressing1 = false;
      Keyboard.release('d');   
     }
  }
}

Let’s try this again, more information.

A 4x4 keypad will only give you 16 keys, for 32 you need a 4X8 or some other combination that adds up to 32.

This is the closest I have it is an 8X8 giving you 64 keys, but you can always cut it down.

http://www.thebox.myzen.co.uk/Hardware/Econo_Monome.html

This is a 4 by 4 matrix.
http://www.thebox.myzen.co.uk/Hardware/Mini_Monome.html

Hello @LarryD,

The code I wrote above works completely, but I am using a pin with this code block. Since the pro micro has a limited number of pins, I need to solve this with a 4x4 keypad. Logically I will control 16 buttons using 8 pins.

The word control means you make the button do something, you mean read the buttons.
This is not the same as reading a 4by 4 key pad it is reading 16 buttons.

For that use two shift registers.

What about a 4X4 and a single shift key?

Yes that will do it as well, but it is less convenient to use.

Indeed, but it works well on handheld calculators.

@nihatcengiz

You can use one pin for an IR receiver and a multi button remote control.

image

image

I would start with the Keypad library and the MultiKey example that comes with it. I would then change this part of the sketch to send the desired Keyboard.press() on PRESSED and the desired Keyboard.release() on RELEASED.

            if ( kpd.key[i].stateChanged )   // Only find keys that have changed state.
            {
                switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                    case PRESSED:
                    msg = " PRESSED.";
                break;
                    case HOLD:
                    msg = " HOLD.";
                break;
                    case RELEASED:
                    msg = " RELEASED.";
                break;
                    case IDLE:
                    msg = " IDLE.";
                }
                Serial.print("Key ");
                Serial.print(kpd.key[i].kchar);
                Serial.println(msg);
            }

If it is all single ASCII characters like your example "Keyboard.press('d');" then it's very easy:

            if ( kpd.key[i].stateChanged )   // Only find keys that have changed state.
            {
                switch (kpd.key[i].kstate) 
                {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                  case PRESSED:
                    Keyboard.press(kpd.key[i].kchar);
                    break;

                  case RELEASED:
                    Keyboard.release(kpd.key[i].kchar);
                    break;
                }
            }