Skip to content

Instantly share code, notes, and snippets.

@smching
smching / maximum_retries.ino
Created March 30, 2016 13:58
Arduino电子密码锁
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
}
}
@smching
smching / reset_RetryCount.ino
Created March 30, 2016 13:56
Arduino电子密码锁
void resetRetryCount() {
retryCount = 0; //reset retry count
reached_maximum_retries = false; // enable keyboard input
welcome();
}
@smching
smching / retry_Count.ino
Created March 30, 2016 13:54
Arduino电子密码锁
if (retryCount > 0) { //if someone have entered wrong password
if (millis() >= previousMillis + AUTO_RESET_RETRY_COUNT * 60000) {
resetRetryCount();
}
}
@smching
smching / runEvent_AnyTime.ino
Created March 30, 2016 13:53
Arduino电子密码锁
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();
}
@smching
smching / main_loop.ino
Created March 30, 2016 13:50
Arduino电子密码锁
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();
}
}
@smching
smching / load_Configuration.ino
Created March 30, 2016 13:48
Arduino电子密码锁
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
}
@smching
smching / initialize_EEPROM.ino
Created March 30, 2016 13:46
Arduino电子密码锁
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();
@smching
smching / reset_settings.ino
Created March 30, 2016 13:44
Arduino电子密码锁
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
@smching
smching / lcd1602_pos_system
Created March 30, 2016 13:04
Arduino与I2C/TWI LCD1602模块
// 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
@smching
smching / lcd1602.ino
Created March 30, 2016 13:02
Arduino与I2C/TWI LCD1602模块
//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;