KeyPad 4x4 Row Column Progression for LCD 16x2

#include <LiquidCrystal_I2C.h> 
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <Keypad.h>
const int ROW_NUM = 4; //four rows
const int COLUMN_NUM = 4; //four columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'1','2','3', 'A'},
{'4','5','6', 'B'},
{'7','8','9', 'C'},
{'*','0','#', 'D'}
};

int R = 0;
int C = 0;
int R1 = 1;
int C1 = 0;

byte pin_rows[ROW_NUM] = {A15, A14, A13, A12}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {A11, A10, A9, A8}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );

void setup(){
 lcd.init(); // display initialization
 lcd.clear();
 lcd.backlight(); // activate the backlight
}

void loop()
{
char key = keypad.getKey();
if(key) //press a key on the 4x4 matrix keypad
{
  lcd.print(key);
  C++;

if(C>15)
  {
  lcd.setCursor(C1, R1);
  lcd.print(key);
  C1++;
  }
if(C1>16)
  {
  lcd.clear();
  C=0;
  R=0;
  }
if(C==0)// && R==0)
  {
  lcd.print(key);
  C++;
  }
}
}




Here When I use to press keys on keypad =>

  1. It starts printing from location (0,0) to (15,0)
  2. Then gets switch to Row 1 from (0,1) to (15,1)
  3. Then Screen gets clear !!

At this point I want to start the above 3 steps of function to continue the printing

But here in my code :

After clear screen , the keys are getting printed on a single location (0,0) displaying one key at a time only and it is not proceeding to (1,0) , (2,0) . . . . and so on like that !!!!!

Please help me in getting this . .

There's no R1++, nor R++, whatever it should be.....

Try this code:

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <Keypad.h>
const int ROW_NUM = 4; //four rows
const int COLUMN_NUM = 4; //four columns
char keys[ROW_NUM][COLUMN_NUM] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

int R = 0;
int C = 0;
int R1 = 1;
int C1 = 0;

byte pin_rows[ROW_NUM] = {A15, A14, A13, A12}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {A11, A10, A9, A8}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );

void setup() {
  lcd.init(); // display initialization
  lcd.clear();
  lcd.backlight(); // activate the backlight
}

void loop()
{
  char key = keypad.getKey();
  if (key) //press a key on the 4x4 matrix keypad
  {
    lcd.print(key);
    C++;
    if (C > 16)
    {
      lcd.setCursor(C1, R1);
      lcd.print(key);
      C1++;
    }
    if (C1 > 16)
    {
      lcd.clear();
      C = 0;
      R = 0;
      C1 = 0;
      lcd.setCursor(C, R);
      lcd.print(key);
      C++;
    }
  }
}
1 Like

OK Done !! Then how to move without these two ???

Sorry ,
not is if (C > 15) and if (C1 > 15).

Correct is if (C > 16) and if (C1 > 16).

Wowwww !!!!!!!!!
That is working :astonished: :open_mouth:

Great !!!

One thing I want to add as a feature here !!

As all the time i need to press keys repeatedly say key 1 so many times to print 1111111

Is there any option that I use to press and hold a single key and the printing will start automatically 11111111111111 like that until I release the key ????????

Ok Le me check !!

Oh Yes yes It was switching after 15 immediately
and now its all the way OK !!!

Please check #6 I am having a query there !!!

any solution regarding #6 sir ??

I don't know if it's possible.
You need to study the Keypad.h library to see if there is such a function to repeat characters.

Any good link to study that way ??

I found it on google:

"Using keypad.h HOLD to fire off continuous data?

Ya OK Le Me Go Thru it . . . Thanks !!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.