#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
const byte ROW_NUM = 4; // four rows
const byte COLUMN_NUM = 4; // four columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; // connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; // connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM);
void setup() {
// put your setup code here, to run once:
lcd.init();
lcd.backlight();
lcd.begin(16,2);
// lcd.print("hi");
}
void loop() {
// put your main code here, to run repeatedly:
String str1 = "13";
String str2 = "";
// char str3[] = {};
char key = keypad.getKey();
// lcd.clear();
if (key){
if (key == '#'){
lcd.print(str2 == str1);
} else {
lcd.clear();
str2 += key;
// str2.concat(key);
lcd.print(str2);
}
}
}
hello there
got a trouble
when trying to compere entered 2 digits 13 from keypad and checking whether they match the str1, lcd always returns 0. I tried different methods whith strings and arrays but result the same(
Every time you add a String before variable name you created a new String instance
just use str2 rather than String(str2)
And second - you defined str2 as local variable of loop() procedure. It means that it will be cleared every time the loop restarts and all previously entered keys will lose.