Hello,
I am new to programming and new to the Arduino community and was hoping one of you could provide some guidance. Basically I am trying to limit two input from keypad. I figured out how to set up the keypad and can correctly display the button I pressed. I am struggling to limit 2-digit number value eg 50. Any advice would be greatly appreciated!

``````void checknumber(int x){
if (firstnumber == 99) { // Check if this is the first number entered
firstnumber=x;
String displayvalue = String(firstnumber);  //  Transform int to a string for display
lcd.setCursor(10,0);
lcd.print(displayvalue); // Redraw screen

} else {
if (secondnumber == 99) {  // Check if it's the second number entered
secondnumber=x;
String displayvalue = (String(firstnumber) + String(secondnumber));

lcd.setCursor(10,0);
lcd.print(displayvalue);
lcd.print(" " );
}
}
}
``````

You need to post the code you have written so far. It will give more context to the question you are asking.

It is not clear what you mean by limiting two-digit numbers. Do you want to limit the input to two digits, or limit the value of the number?

on a keypad, isn’t there usually an “enter” key that indicates when a complete number has been entered? what about 5 vs 50 or 100?

(deleted)

Take a look at Keypad data entry it may provide you with some ideas but it is not clear what problem you are having

I mean limitimg the value of the input number.

I posted the code.I mean limiting input number value.

Did you look at the link I posted above ?

If you get the number as an integer rather than some Frankenstein's monster collection of individual String digits then it is easy to test its value and react accordingly if it is out of range

Is ‘firstnumber’ one of the digits of the number and ‘secondnumber’ another digit?
If so this is completely the wrong way to go about entering a number.

Otherwise your posted code tells us nothing because you’ve decided to subscribe to snippets-r-us.

``````#include <stdio.h>
#include <string.h>

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

void loop() {
int x;
}

static char serialBuffer[3] = {'\0', '\0', '\0'};
static unsigned long serialInTimestamp;
if (serialBuffer[0] > '\0') {
if (millis() - serialInTimestamp >= 100UL) {
memset(serialBuffer, '\0', sizeof(serialBuffer));
}
}
if (Serial.available()) {
if (c >= '0' && c <= '9') {
serialInTimestamp = millis();
serialBuffer[0] = c;
}
else {
memset(serialBuffer, '\0', sizeof(serialBuffer));
}
}
else if (charsRead == 1) {
if ( c >= '0' && c <= '9') {
serialBuffer[1] = c;
serialBuffer[2] = '\0';
x = atoi(serialBuffer);
memset(serialBuffer, '\0', sizeof(serialBuffer));
return true;
}
else {
memset(serialBuffer, '\0', sizeof(serialBuffer));
}
}
else {
memset(serialBuffer, '\0', sizeof(serialBuffer));
}
}
return false;
}
``````

Hello guys!
so I'm new to coding and was wondering if I could get some help.how can I limit two digit values for keypad coding? for example 1-50.

``````    if (1 > val)
val = 1;
if (50 < val)
val = 50;
``````

Can u code for a full example? I am just a newbie.

Have you thought about what you want your sketch to do if someone tries to enter an invalid value?

Having another suck of the sav are you?