Good day everyone!
I need to know how to enter double digits onto a lcd . For now i have no problem entering from digits 0-9, but what do i need to do in order to enter the digit 10> ?

If i enter 1 , then 0, it will just change accordingly on the lcd, 1, then 0. Thanks for all your help in advance

Think about this for a moment. The computer really can't know unless you have some way to tell it that the number is complete. Like a # key or a timeout.

You say that you already have it working for single digits.

Please post the code you already have, which works for single digits. Then maybe we can help you figure out how to modify it for double digits.

Multiply what you have by ten and add the new digit.

This is my code. ignore the bottom part , i just want to show you how i code they keypad with the LCD. Thanks!

fyp2.ino (1.38 KB)

OPâ€™s code formatted and inlined.

Youâ€™d be surprised how many bugs youâ€™ll find just formatting code. Thereâ€™s a reason we do it with the indenting and the blocks all lined up a certain way and it isnâ€™t just because itâ€™s pretty.

``````#include <LiquidCrystal.h>

const byte rows = 4; //four rows
const byte cols = 3; //three columns
char keys[rows][cols] = {
Â  {'1', '2', '3'},
Â  {'4', '5', '6'},
Â  {'7', '8', '9'},
Â  {'#', '0', '*'}
};
byte rowPins[rows] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad left first 4
byte colPins[cols] = {6, 7, 8}; //connect to the column pinouts of the keypad right last 3
const int rs = A7, en = A2, d4 = 9, d5 = 10, d6 = 11, d7 = 12;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int i = 0;
int led = 14;
void setup() {
Â  // put your setup code here, to run once:
Â  Serial.begin(9600);
Â  lcd.begin(16, 2);
Â  pinMode( led, OUTPUT);
}

void loop() {
Â  // put your main code here, to run repeatedly:
Â  lcd.setCursor(0, 0);
Â  lcd.print("Select item");
Â  lcd.display();
Â  char key = keypad.getKey ();
Â  if (key != NO_KEY) {

Â  Â  Serial.println(key);
Â  Â  lcd.setCursor (0, 1);
Â  Â  lcd.print(key);
Â  Â  lcd.display();
Â  }

Â  if (key != NO_KEY)

Â  {
Â  Â  switch (key)

Â  Â  {
Â  Â  Â  case '1':
Â  Â  Â  Â  digitalWrite(led, HIGH);
Â  Â  Â  Â  delay(1000);
Â  Â  Â  Â  digitalWrite(led, LOW);
Â  Â  Â  Â  lcd.clear();
Â  Â  Â  Â  break;

Â  Â  Â  case '2':
Â  Â  Â  Â  digitalWrite(led, HIGH);
Â  Â  Â  Â  delay(500);
Â  Â  Â  Â  digitalWrite(led, LOW);
Â  Â  Â  Â  delay(500);
Â  Â  Â  Â  lcd.clear();
Â  Â  Â  Â  break;

Â  Â  }

Â  Â  lcd.clear();
Â  Â  lcd.setCursor (0, 0);
Â  Â  lcd.print("Enter Amount");
Â  Â  lcd.display();
Â  Â  lcd.setCursor (0, 1);
Â  Â  lcd.print(key);
Â  Â  lcd.display();
Â  }
}
``````

Instead of just printing key to the display, create yourself a variable and use key to increase or decrease it as you will and then display that variable to the display.

Delta_G:
Multiply what you have by ten and add the new digit.

``````int myValue = 0;

////Â  in loop

// get a key from the keypad

key -= 48;Â  //Â  Because you have ascii codes instead of number in the matrix

myValue = (myValue * 10) + key;Â   // add key digit to the end of myValue.
``````

Hi delta, thanks for the fast response!
Im just wondering why is key-=48?

bob112112:
Hi delta, thanks for the fast response!
Im just wondering why is key-=48?

I told you right in the comment next to it.

In your matrix your first button doesn't give 1, it gives '1' which is equal to 49. http://www.asciitable.com/

Thank you so much ! On a side note, how do i enter store the value i want now? For example , if i want to store the value 20, how do i " Enter " it as a variable and store it? Thanks in advance!

You write a code that checks for some other key that isn't a digit, like # or something and if it is that key then instead of adding it to your digit you mark that your number is complete.