Entering 3 digits

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.

HazardsMind... For what it's worth... When I look on the term, I see about 30 seconds worth of 0's then random characters.. all this time, the TX LED is lit on the Mega

Here this is what I tried to do, it does not have anything to do with KEYPAD, but it may give you a little push.

int currentCommand = 0;
char Data[256];

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

void loop() {
  if( Serial.available())       // if data is available to read
  {
    char c= Serial.read();
    if (c == '.'){
      
        long i=atol(Data);
        Serial.println(i);
        Serial.println(currentCommand);
        while(currentCommand !=0){
        Data[currentCommand--] = 0;
        }
      }
    else {   
      Data[currentCommand++] = c;
    }
  }
}

Im still trying to figure out the Keypad code, myself.

The getKey() method is NOT a blocking function. Most of the time when it is called, no key is being pressed, so the return value is NO_KEY. You need to add another if statement after the call to getKey():

  char key = keypad.getKey();
  if(key != NO_KEY) // Do nothing is no key is pressed
  {
    if (key != '*')
    {
       keyIn += key;
    }
    else
    {
       // The else stuff
    }
  }

Ok this should work with the added NO_KEY condition

//these two need to go at the top of the screen
int currentCommand = 0;
char Data[2];



void loop(){
if(key != NO_KEY) // Do nothing if no key is pressed, incorporated from PaulS's example.
  {
  char key = keypad.getKey();
  
  if (key != '*'){
    Data[currentCommand++] = key;
}

else {
    int keyIn = atoi(Data);
    lcd.begin(16,0);
    lcd.setCursor(6,0);
    lcd.print(keyIn);     
    lcd.print("  ");
    Serial.println(keyIn);
    while(currentCommand !=0){   // This can be used for any array size, 
    Data[currentCommand--] = 0; //clear for new data
        }
     } 
  }
}