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?
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.
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;
}
}