can i use a 4×4 keypad as 4×3?÷

hi
I'm using a 4×4 keypad for my project,and I find out I don't need a column (A,B,C,D column)
also I need another free digital pin
so I want to know,is it possible to remove a column in my codes,without ruining the whole program,and if the answer is YES,how can I do that?
in other words,can I use a 4×4 keypad like it is 4×3 with same codes?

Yes.

Show us your t**s code!

Do you have A4 & A5 free, or used for other i2c devices? If so, it's pretty easy to use a pcf8475 chip to interface with the keypad and use all 16 buttons with only 2 pins.

#include <Keypad.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
const byte numRows= 4;
const byte numCols= 4;
char keymap[numRows][numCols]=
{
{‘1’, ‘2’, ‘3’, ‘A’},
{‘4’, ‘5’, ‘6’, ‘B’},
{‘7’, ‘8’, ‘9’, ‘C’},
{’*’, ‘0’, ‘#’, ‘D’}
};

byte rowPins[numRows] = {9,8,7,6};
byte colPins[numCols]= {5,4,3,2};
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
void setup()
{
lcd.begin (16,2);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home ();
lcd.print(“Press a key”);
delay(2000);
}

void loop()
{
char keypressed = myKeypad.getKey();
if (keypressed != NO_KEY)
{
lcd.clear();
lcd.print(keypressed);
}
}

it’s a part of my whole program,just matching I2C LCD and keypad
which part of this code should be removed to let my 4×4 kepad work jyst like a 4×3?

PaulRB:
Do you have A4 & A5 free, or used for other i2c devices? If so, it’s pretty easy to use a pcf8475 chip to interface with the keypad and use all 16 buttons with only 2 pins.

i already used those pins for my LCD

You've been very lucky, the forum has not corrupted your code. Even so, please modify your post and put the code tags in.

Using the LCD is the reason you are running out of pins. Get an i2c backpack for your LCD. Then your LCD and keypad can share just 2 pins, freeing up, what, 12 pins?

Perhaps you might have looked at his code, such as it is, and noticed he is already using the "backpack" which is why he said

R0UGH:
I already used those pins for my LCD

:astonished:

So yes indeed, use a "port expander" and require no Arduino pins to interface it!

Problem: Need a different keypad library!

Sorry, I do not know how to "blank" out a row in that keypad library. ... Arrgh! It is perfectly obvious! :astonished:

You define either "numRows" or "numCols" to be the number of rows or columns you actually need. The library is written correctly.

Too much time wasted. :roll_eyes: