Codeing_simple_password-checker

#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(

I'll appreciate any help
thx

try printing the strings rather than just the comparison

you mean in 49th line print like this:

      lcd.print(String(str2));

?

I tried this but haven't worked< unluck(

yes
make sure both strings are the same value when you think the == is failing

tried that too but now lcd even doesn't print str2, but when pressing '#' it returns 0((

Please show your revised code

#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(String(str2) == String(str1));
    } else {
      lcd.clear();
      String(str2) += key;
      // str2.concat(key);
      lcd.print(String(str2));
    }
  }

}

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.

that not what i meant

assuming the LCD can print only one line, it should be either

lcd.print(String(str2);

or

lcd.print(String(str1);

to verify you are comparing 2 strings that are the same

1 Like

ok i tried to modify and here what i got:

#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);


  String str1 = "3456";
  String str2 = "34";

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:



  // char str3[] = {};
  
  char key = keypad.getKey();

  // lcd.clear();
  if (key){
    if (key == '#'){
      lcd.setCursor(1, 1);
      lcd.print(String(str2));
    } else {

      str2 += key;
      // str2.concat(key);
      lcd.print(str2);
    }
  }


}

so here I just need to enter 5 and 6 and compere both strings
but I don't see half of monitor(

finallyyyyyy
i got it
thanks very much I really appreciate your help
you gave nice ideas
now I'm satisfied
it shows 1, passwords are equel

you too thanks a ton!!!!!!

should str2 be reset after each attempt

2 Likes

yeah i'm overthinking how to do it

but it would be nice if i find out how to fix that i don't see half of lcd

looks like the display is 16 columns and 2 rows. should this be 16,2 instead of 20,4?

tried
result the same(

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.