Total newbie here, I'm trying to symplify this code :
void loop(){
char keyPress = keypad.getKey();
if ((keyPress == '0') || (keyPress == '1') || (keyPress == '2')|| (keyPress == '3')|| (keyPress == '4')|| (keyPress == '5')
|| (keyPress == '6')|| (keyPress == '7')|| (keyPress == '8')|| (keyPress == '9')&& pos < 13){
//blabla
}
}
I'm thinking about making a function and call it like :
if(Name_of_Function){
//blabla
}
But I don't know how to do it. Any help ?
thialdyn:
if(Name_of_Function)
How about
if (Name_of_Function (keyPress))
?
1 Like
It's already in the language...
if ( isdigit(keyPress) and pos < 13) { ...
3 Likes
Oh, didn't know about, thanks, it's working
gcjr
February 19, 2022, 10:51pm
5
void loop(){
char keyPress = keypad.getKey();
if (pos < 13) {
switch (keypress) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
//blabla
break;
case '*':
case '#':
break;
}
}
}
2 Likes
Something like:
if ((keyPress >= '0') && (keyPress <= '9') && pos < 13) {
or
if (isDigit(keyPress) && pos < 13) {
2 Likes
system
Closed
August 19, 2022, 11:49pm
8
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.