[HELP] Edit variable value using keypad

Hello guys! I'm new here in the community. I'm in need of advice on how to edit variable value using keypad. Idk which approach will I use since every press on a keypad replace the previous value on a variable.

Scenario:

minTemp = 30;

I want to change this value to 35 via keypad but if I do this;

minTemp = Key; // Key = value of keypress

If I press 3 and 5 consecutively, minTemp value is 5 not 35. What approach should I do?

If I press 3 and 5 consecutively, minTemp value is 5 not 35. What approach should I do?

Post your code. Apparently, you need another key that means "use this data" (and one that means "oops"). Save the key values in an array until the value is the one that means "use this data". When that one arrives, convert the stored characters to an int (using atoi()) and use that as the new value.

First, I'd like to thank you for replying to this thread. :slight_smile:

This is the part mentioned above.

if (editState == true) {
lcd.setCursor(0, 0);
lcd.print("Choose settings:");
lcd.setCursor(0, 1);
lcd.print("A:TMP B:HMD C:SM");

if (Key == KEY_A) {
setTemp = true;
lcd.clear();
lcd.print("Temp(MIN):");
}

if (setTemp == true) {
if (Key != KEY_NOT_PRESSED && setTemp == true) {
Data[data_count] = Key; // store char into data array
lcd.setCursor(data_count, 1); // move cursor to show each new char
lcd.print(Data[data_count]); // print char at said cursor
data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
}
}
minTemp = atoi(Data);
lcd.print("Min Temp: ");
lcd.print(minTemp);

}

This is my current code but I'm still dealing with another problem that the code doesn't enter if (Key == KEY_A) statement.

if (setTemp == true) {
        if (Key != KEY_NOT_PRESSED && setTemp == true) {
          Data[data_count] = Key; // store char into data array
          lcd.setCursor(data_count, 1); // move cursor to show each new char
          lcd.print(Data[data_count]); // print char at said cursor
          data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
        }
      }
      minTemp = atoi(Data);

Data is NOT a string. It is a piss-poor practice to pass a non-string to a function that expects a String.

Make Data a string, after you learn what distinguishes a string from char array.

This is my current code but I'm still dealing with another problem that the code doesn't enter if (Key == KEY_A) statement.

And why should it? You would have had to read a key press, and have stored the value in Key, before the if statement is evaluated. There is no proof that this is the case.

PaulS:

if (setTemp == true) {

if (Key != KEY_NOT_PRESSED && setTemp == true) {
          Data[data_count] = Key; // store char into data array
          lcd.setCursor(data_count, 1); // move cursor to show each new char
          lcd.print(Data[data_count]); // print char at said cursor
          data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
        }
      }
      minTemp = atoi(Data);



Data is NOT a string. It is a piss-poor practice to pass a non-string to a function that expects a String.

Make Data a string, after you learn what distinguishes a string from char array.
And why should it? You would have had to read a key press, and have stored the value in Key, before the if statement is evaluated. There is no proof that this is the case.

I am trying to use this approach in setting the temp value.
http://playground.arduino.cc/Main/KeypadPassword

Thing is it should go inside that if statement since I set setTemp to true so it will collect and store data to array and set that data to minTemp variable.

Thing is it should go inside that if statement since I set setTemp to true so it will collect and store data to array and set that data to minTemp variable.

You have two if statements. It does evaluate the first if statement as true. You are not then waiting for a key press or reading the key, so there is no basis to assume that the second if statement should be evaluated to true.