Keypad, I2c display, password

Hey guys, I found this code in tinkercad that should create password and let user to try to guess the password using keypad. He should only have 3 tries and if he fails, it should turn off. But it doesn´t work. Please help.

#include <LiquidCrystal_I2C.h>  /*include LCD I2C Library*/
#include <Keypad.h>
#define Password_Length 5
const byte ROWS = 4; 
const byte COLS = 4; 

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {9, 8, 7, 6}; 
byte colPins[COLS] = {5, 4, 3, 2}; 

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

LiquidCrystal_I2C lcd(32,16,2);  /*I2C scanned address defined + I2C screen size*/

char Data[Password_Length]; 
char Master[Password_Length] = "1234"; 
byte data_count = 0, master_count = 0;
char customKey;
int num = 1;

void setup() {
  lcd.init();  /*LCD display initialized*/
  lcd.clear();     /*Clear LCD Display*/
  lcd.backlight();      /*Turn ON LCD Backlight*/;
  Serial.begin(9600);
}
void loop() {
  if(data_count < Password_Length-1){
    lcd.setCursor(0,0);   /*Set cursor to Row 1*/
    lcd.print("Zadej heslo"); /*print text on LCD*/
    customKey = customKeypad.getKey();
     if (customKey){
    Data[data_count] = customKey; 
    lcd.setCursor(data_count,1); 
    lcd.print(Data[data_count]); 
    data_count++; 
    }
  }

 

  if(data_count == Password_Length-1){
    lcd.clear();

    if(!strcmp(Data, Master)){
      
      lcd.print("Spravne"); 
      delay(2000);
    }
    else{
      lcd.print("Spatne");
      num++;
      data_count = 0;
      delay(1000);
      if(num == 4){
        lcd.clear();
        lcd.print("3x spatne");
        delay(2000);
        lcd.clear();
        lcd.print("Blokuji");
        delay(2000);
        lcd.noDisplay();
      }
    }
  
  }
  
}

Welcome to the forum

More details please

What does it do ?
What doesn't it do ?

LiquidCrystal_I2C lcd(32,16,2);  /*I2C scanned address defined + I2C screen size*/

This line looks very odd but there are many LCD libraries with the same name. Which one are you using ?

The address of an LCD display should be in hex ?

1 Like

@warshak - There are two ways to see this value of "32":
Convert as hex to hex: HEX 32 = 0x32
Convert as dec to hex: DEC 32 = 0x20

You can use any I2C scanner to find the LCD address:

Welcome, Does the code actually work on the designer's system? Can you post an annotated schematic, I have a lot of drawings with an LCD and keypad. Also post a link to where you got the code and save us a lot of guessing.

@warshak Welcome to the forum..
threw this into a simulator, changed screen address to match sim..
seems to work as you describe..
so probably like others have pointed out, wrong address??
could be wiring issue too..

Your project simulated..

good luck.. ~q

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