I have this code for password locking system operating 2 Locks
#include <Keypad.h>
const int ROW_NUM = 4; //four rows
const int 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 );
#define password_Length 2
char userInput[password_Length];
char password[2];
char initial_password[2];
int currentposition=0;
const String password_1 = "111"; // change your password here
const String password_2 = "2222"; // change your password here
String input_password;
char customKey;
byte pressCount = 0;
voidSetup()
{
}
void loop()
{
char key = keypad.getKey();
if (key)
{
if(key == 'A')
{
input_password = "";
lcd.setCursor(0, 1);
lcd.print("Reset");
delay(500);
}
else if
(key == 'B')
{
if (input_password.length() > 0)
{
lcd.setCursor(input_password.length(), 1); // move cursor to the last added character
lcd.print(' '); // Replace it with a blank
input_password.remove(input_password.length() - 1);
}
else if(key == '#')
{
lcd.setCursor(0,1);
lcd.print(" ");
if (input_password == password_1)
{
digitalWrite(PIN11,1);
}
else if (input_password == password_2)
{
digitalWrite(PIN12,1);
}
else
{
lcd.setCursor(0,1);
lcd.print("Denied");
delay(5);
}
input_password = "";
}
else
{
if(input_password.length() == 0)
input_password += key; // append new character to input password string
lcd.setCursor(input_password.length(), 1); // move cursor to new position
lcd.print(key); // print key showing the character
//lcd.print('*'); // print * key as hiden character
}
}
I got it here in forum only and very thankful for that
I find no problem and its working very fine
But I want to limit the length of digit to 3 and the system should not allow to enter more than 3 digits
I mean when someone is going to press 1234
then after 123 nothing will get displayed and nothing is going to happen
It ll not proceed to display after 123
Please guide me with above code
So many people advised me so many things and i added all that in code but its not working