Hello,
I'm looking for your help, I'm working on this code and I tried to replace delay() with millis() to add more functions that will run right after the delay(), but to be honest I'm not totally understanding how it precisely works, I tried but I think I'll understand practicing, so here's the full code before millis()
[code]
#include <Keypad.h>
#include <LiquidCrystal.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] =
{
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {6 , A1, 2, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 7, 3}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
const int rs = 13, en = 12, d4 = 11, d5 = 10, d6 = 9, d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int RELAY_PIN = A0; // the Arduino pin, which connects to the IN pin of relay
const String password_1 = "03121990"; // change your password here
String input_password;
int cursorColumn = 0;
const int Beep = A2;
void setup()
{
input_password.reserve(16); // maximum input characters is 33, change if needed
pinMode(RELAY_PIN, OUTPUT); // initialize pin as an output.
digitalWrite(RELAY_PIN, HIGH); // lock the door
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode (A2, OUTPUT);
}
void loop()
{
{
lcd.setCursor(0, 0);
lcd.print("ENTER PASSWORD:");
}
char key = keypad.getKey();
{
if (key)
tone(A2, 2500, 100);
}
if (key)
{
if(key == '*')
{
input_password = ""; // reset the input password
lcd.clear();
} else if(key == '#')
{
lcd.clear();
if(input_password == password_1)
{
lcd.setCursor(0, 0);
lcd.print("CORRECT!");
lcd.setCursor(0, 1);
lcd.print("ACCESS GRANTED!");
digitalWrite(RELAY_PIN, LOW); // unlock the door for 20 seconds
delay(2000);
lcd.clear();
delay(10000);
digitalWrite(RELAY_PIN, HIGH); // lock the door
}
else
{
lcd.setCursor(0, 0);
lcd.print("INCORRECT!");
lcd.setCursor(0, 1);
lcd.print("ACCESS DENIED!");
delay(2000);
lcd.clear();
}
input_password = ""; // reset the input password
}
else
{
if(input_password.length() == 0) {
lcd.clear();
}
input_password += key; // append new character to input password string
lcd.setCursor(input_password.length(), 2); // move cursor to new position
lcd.print('*'); // print * key as hiden character
}
}
}
[/code]
appreciate your help!!