This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!reached_maximum_retries) { // if did not reach maximum number of retry | |
char key = keypad.getKey(); //waiting for keyboard input (non blocking) | |
if (key != NO_KEY){ //if press a key | |
beep(); | |
delay(30); //debounce | |
if (key == '#') enterPasswordForMenu(); //require to enter password before proceed to menu selection | |
else enterPasswordToRelease_DoorLock(key); //otherwise proceed to enterPasswordToRelease_DoorLock routine | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void resetRetryCount() { | |
retryCount = 0; //reset retry count | |
reached_maximum_retries = false; // enable keyboard input | |
welcome(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (retryCount > 0) { //if someone have entered wrong password | |
if (millis() >= previousMillis + AUTO_RESET_RETRY_COUNT * 60000) { | |
resetRetryCount(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void runEventAnyTime() { | |
// press a switch to release door lock without enter password | |
press_release_lock_switch(); | |
// press a switch to ring the bell | |
press_bell_switch(); | |
// read tag & release door lock if verified | |
read_RFID(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void loop(){ | |
runEventAnyTime(); // codes inside runEventAnyTime() will keep on updating | |
print_date_time(); | |
// retryCount increase by one each time an incorrect password has been entered | |
// retryCount will reset to zero when idle for one minute (set by AUTO_RESET_RETRY_COUNT) | |
if (retryCount > 0) { //if someone have entered wrong password | |
if (millis() >= previousMillis + AUTO_RESET_RETRY_COUNT * 60000) { | |
resetRetryCount(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void loadConfiguration() { | |
eeprom_read_string(USER_PASSWORD_EEPROM_ADDRESS, buf, maxPasswordLength + 1); //read USER password from EEPROM | |
userPassword = buf; //use this password to release door lock | |
eeprom_read_string(ADMIN_PASSWORD_EEPROM_ADDRESS, buf, maxPasswordLength + 1); //read ADMIN password from EEPROM | |
adminPassword = buf; //use this password to enter menu selection | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void initializeEEPROM(){ | |
strcpy(buf, "1234"); //set password to 1234 | |
eeprom_write_string(USER_PASSWORD_EEPROM_ADDRESS, buf); //write password to EEPROM | |
strcpy(buf, "1234"); //set password to 1234 | |
eeprom_write_string(ADMIN_PASSWORD_EEPROM_ADDRESS, buf); //write password to EEPROM | |
DEBUG_PRINTLN("Initialize completed"); | |
lcd.clear(); | |
lcd.print("Initialized."); | |
delay(1000); | |
playOKTone(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void reset_settings() { | |
unsigned long start_hold = millis(); // mark the time | |
int HOLD_DELAY = 5000; // Sets the hold delay | |
DEBUG_PRINTLN("Please keep on pressing for 5 sconds."); | |
while (sw_state == LOW) { | |
sw_state = digitalRead(RESET_SETTINGS_PIN ); // read input value | |
if ((millis() - start_hold) >= HOLD_DELAY){ // for longer than HOLD_DELAY | |
//initialize_is_running = true; // keep loop running even though RESET_SETTINGS_PIN is low | |
initializeEEPROM(); | |
break; //break the loop after initialized |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample code for I2C/TWI LCD1602 Module | |
// read data from serial port & print to LCD | |
// Compatible with the Arduino IDE 1.0 | |
#include <Wire.h> | |
#include <LiquidCrystal_I2C.h> | |
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display | |
String inputString = ""; // a string to hold incoming data | |
boolean stringComplete = false; // whether the string is complete |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Sample code for I2C/TWI LCD1602 Module | |
//Compatible with the Arduino IDE 1.0 | |
#include <Wire.h> | |
#include <LiquidCrystal_I2C.h> | |
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display | |
String myString = "ediy.com.my"; | |
int myInteger = 123; | |
float myFloat = 123.45; |