Entering 3 digits

Nub here again..
I'm actually making progress with my project.. and thanks to all who have helped..As it stands now, I can enter digits but the display only displays 1 digit at a time..

What do I need to add to allow me to enter 3 digits from the keypad and have the three digits display on my LCD when I hit the * key..

The code I'm using is :

/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {28, 26, 24, 22}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {31, 33, 35}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
Serial.begin(9600);

}

void loop(){
char key = keypad.getKey();

if (key){
lcd.begin(16,0);
lcd.setCursor(6,0);
lcd.print(key);
lcd.print(" ");
Serial.println(key);
}
}

Change your loop to this.

void loop(){

  char key = keypad.getKey();
  
  if (key != '*'){
String keyIn += key;
}

else {
    lcd.begin(16,0);
    lcd.setCursor(6,0);
// int keyDisp = keyIn.toInt();
    lcd.print(keyIn); // if you don't get the correct data, then uncomment previous line and change keyIn to keyDisp
    lcd.print("  ");
    Serial.println(keyIn);
    keyIn = "";  //clear for new data
  }
}

I made an edit

added the new loop.. Now I get a compile error at the: String keyIn += Key line

HELP !!!!

declair "String keyIn" at the top of your code with everything else and delete "String" inside the loop.

I thought that might happen, sorry

I declared it ... Remarked out the string... now it just keeps erroring on anything added

Of course, using the String class to collect a fixed number of characters is not necessary. Doing so will make it difficult to implement a backspace key.

A 4 element char array and an index would be much better - 3 characters and a NULL terminator. Increment the index each time you add a character and NULL. Decrement the index each time the backspace key is pressed.

What errors did you get, copy and paste them.

Also where did you get the keypad library, could you post a link?

I dont understand why you got errors, but this compiled. Try it.

/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
String keyIn;

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {28, 26, 24, 22}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {31, 33, 35}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
  
}
  
void loop(){

  char key = keypad.getKey();
  
  if (key != '*'){
    keyIn += key;
}

else {
    lcd.begin(16,0);
    lcd.setCursor(6,0);
// int keyDisp = keyIn.toInt();
    lcd.print(keyIn); // if you don't get the correct data, then uncomment previous line and change keyIn to keyDisp
    lcd.print("  ");
    Serial.println(keyIn);
    keyIn = "";  //clear for new data
  }
}

@PaulS
What backspace button, the only buttons dcr_inc has are what is on that keypad. Unless dcr_inc uses "#" as the backspace button.

What backspace button, the only buttons dcr_inc has are what is on that keypad. Unless dcr_inc uses "#" as the backspace button.

There may not be a backspace key yet. But, eventually, OP may decide that one is needed. It's best to plan for what may be needed, not just what IS needed.

A String to handle 3 character entry is just plain lazy.

Ok.. I used the code that was last supplied,.. I un remarked the int keyDisp = keyIn.toInt(); line.. Now I get a 0 on the lcd when I input the * key.. The TX LED on the Mega stays on for approx 30 seconds.. No other key does any thing.. No digits show on the LCD or Term.. The code is exactly what was provided by HazardsMind

True, but it is less coding and less confusing. I always go with simple codes first, then make them more complex. That way if the more complex code doesn't work then I have something to fall back on.

PaulS:
A String to handle 3 character entry is just plain lazy.

Do this instead of String

char keyIn[6]; //If you want 5 digits.

String is lazy and will crash your project due to leaky free().

Folks,
I am to say the least LOST.. What should I delete to add the: char keyLin[6];

Im sorry I'm so lost

OP,

Sorry for the confusion. I will make an attempt to provide a more complete code with the char keyIn version.

HazzardMind has forgotten that getKey can also return NoKey. You need to exclude no key situation so you won't attempt to fill String with NoKey or NOKEY.

Ok, I appologize for the code not working, but keep in mind that I do not have a keypad to test myself, so i'm relying on what dcr_inc is getting.
I could probably simulate it with the serial monitor but thats about it. I don't have any tact buttons or the time to buy or make one right now, so all of this is theoretical.

Folks... I APPRECIATE ALL OF THE INPUT... I am totally at a loss so please accept my appreciation for your knowledge..

Is there any tutorials for what I am trying to do?. I can say I have looked but with no success

In layman's terms, what is this doing?
if (key != '*'){
keyIn += key;

If key does not see * then it is going to keep adding the pressed digits to the string, and when it does see * then it puts out the data.

Ok..I learned something today... THANKS..
for some reason I can not get any digits to appear except when the * is pushed I get a 0 on the LCD

I think the reason you get 0 on the LCD is because of the NoKey function, I think it is constantly filling and overfilling the string with zeros, when nothing is pressed.

I could be wrong.