Setting values from a keypad

So I have set up a keypad and an LCD screen. What I want to do is prompt the user to set some values that I will use later in the program. I have the LCD and the keypad set up, but I am having trouble having the users button presses appear on the screen where I want them (the clear function does not seem to be working for some reason) and I cannot figure out how to take there inputs and set them to a variable.

Here is what I have currently

#include <LiquidCrystal.h>
#include <Keypad.h>

float userset = 0;

LiquidCrystal lcd(24, 22, 32, 30 ,28, 26);

const byte ROWS = 4; 
const byte COLS = 4; 
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'S','0','P','D'}
};
byte rowPins[ROWS] = {23,25,27,29};
byte colPins[COLS] = {31,33,35,37}; 

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



void setup()
{
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.setCursor(2,0);
  lcd.print("Brew Perfect");
  lcd.setCursor(2,1);
  lcd.print("Mandel Tech");
  delay(4000);  
  keypad.setDebounceTime(20);
}

void initLCDKeys()
{
  for (int i = 0; i < sizeof(rowPins); i++)
    pinMode(rowPins[i],OUTPUT);
  for (int i = 0; i < sizeof(colPins); i++)
  {
    pinMode(colPins[i],INPUT);
    digitalWrite(colPins[i],LOW);
  }
}


void loop()
{
  lcd.clear();
  char key = keypad.getKey(); 
  initLCDKeys();
  delay(20);
  if (key != NO_KEY){
    Serial.println(key);
    if (key == 'A')
    {
      lcd.setCursor(2,1);
      lcd.write("          ");
      lcd.setCursor(2,1);
    }
    if (key == 'D')
    {
     userset = 0;                  // Need to set to what user has entered 
  } else
      lcd.print(key);
  }
  lcd.setCursor(2, 0);
  lcd.print("Set Timer");
  lcd.setCursor(0, 1);
  lcd.print("Press F1 to Comp");
  delay(2000);
  lcd.clear();
  lcd.setCursor(2, 1);
  lcd.print(key);
  lcd.setCursor(2, 0);
  lcd.print("Thanks");
  
}

What I would like is as they type it appears on the screen so they can check for accuracy. Pressing A would be a clear function, and D would be submit. I think the code should mostly do that but it is not quite working. Also I cannot figure out how to connect there input with the variable I have defined as "userset" (this is where the code is commented).

Thanks for the help, I am learning as quickly as I can but there is a lot to take in.

void initLCDKeys()
{
  for (int i = 0; i < sizeof(rowPins); i++)
    pinMode(rowPins[i],OUTPUT);
  for (int i = 0; i < sizeof(colPins); i++)
  {
    pinMode(colPins[i],INPUT);
    digitalWrite(colPins[i],LOW);
  }
}

Why? The Keypad library takes care of this!

  char key = keypad.getKey(); 
  initLCDKeys();

I can't begin to imagine WHY you do that AFTER seeing if a key was pressed.

      lcd.write("          ");

Use a method that deals with binary data to deal with ASCII data. Hmmm...

    if (key == 'D')
    {
     userset = 0;                  // Need to set to what user has entered 
  } else
      lcd.print(key);
  }

WTF? Your indenting sucks. NOTHING goes on the same line as ANY }. Use Tools + Auto Format.

  lcd.setCursor(2, 0);
  lcd.print("Set Timer");
  lcd.setCursor(0, 1);
  lcd.print("Press F1 to Comp");
  delay(2000);
  lcd.clear();
  lcd.setCursor(2, 1);
  lcd.print(key);

F1? How the heck is the user supposed to press a non-existent key? Then, regardless of what they do, diddle around for two seconds, then print the key that you didn't read, and that they couldn't press anyway. I see how that works. NOT!

  lcd.setCursor(2, 0);
  lcd.print("Thanks");

You're welcome.

Great super helpful to someone just getting started. BTW the F1 is a reference to the keypad which is what is clearly displayed on the keypad, it was just easier to not name it that in the code. Anyway you had one comment that was useful which to separate lines better, besides that you were just generally an ASS. Like I said I am new to this I am working through this without any help, and with very little resources out there. But thanks for being so welcoming to the community. You are a great example of what not to be like when I am in a position to help others. Have a great day :zipper_mouth_face:

You are a great example of what not to be like when I am in a position to help others.

I hope that when you get to that point, the people you try to help are as appreciative as you are.

There is nothing in your code that does anything you wanted. It shows the first screen "Brew perfect..." then it shows "set timer..." and the key pressed, that's it.

Do you have any more code that your not posting or are you expecting us to create the code for you? As PaulS pointed out, you have a lot of useless garbage in your code. Userset sounds like a login screen that requires a password.

// Need to set to what user has entered

Entered what?

A proper description of what your trying to accomplish would be very helpful.
User enters... which should do this, and if incorrect do something else. We need more info if you want to be pointed in the right direction, otherwise we can't help you.

Ok fair enough, I will work on it some more to get the other parts there before I ask a question. I just figured it was better to do it incrementally, but I guess I might as well put the other parts in so everyone has a better idea of what I am trying to do.

Thanks for being a little more patient with me.

Somebody got a bit upset and moved to
Reddit
8)