#include #include LiquidCrystal_I2C mylcd(0x27,16,2); #include "OneButton.h" // Setup a new OneButton on pin 16. OneButton button1(16, true); // Setup a new OneButton on pin 27. OneButton button2(27, true); #include Servo myservo; int servoPin = 13; String password = ""; String correct_p = "-.-"; //The correct password for the password door // setup code here, to run once: void setup() { Serial.begin(115200); mylcd.init(); mylcd.backlight(); // link the button 1 functions. button1.attachClick(click1); button1.attachLongPressStop(longPressStop1); // link the button 2 functions. button2.attachClick(click2); button2.attachLongPressStop(longPressStop2); myservo.attach(servoPin); mylcd.setCursor(0, 0); mylcd.print("Enter password"); } void loop() { // keep watching the push buttons: button1.tick(); button2.tick(); delay(10); } // ----- button 1 callback functions // This function will be called when the button1 was pressed 1 time (and no 2. button press followed). void click1() { Serial.print("."); password = password + '.'; mylcd.setCursor(0, 1); mylcd.print(password); } // click1 // This function will be called once, when the button1 is released after being pressed for a long time. void longPressStop1() { Serial.print("-"); password = password + '-'; mylcd.setCursor(0, 1); mylcd.print(password); } // longPressStop1 // ... and the same for button 2: void click2() { Serial.println(password); if(password == correct_p) { myservo.write(180); //Open the door if the password is correct mylcd.clear(); mylcd.setCursor(0, 0); mylcd.print("open"); } else { mylcd.clear(); mylcd.setCursor(0, 0); mylcd.print("error"); delay(2000); mylcd.clear(); mylcd.setCursor(0, 0); mylcd.print("input again"); } password = ""; } // click2 void longPressStop2() { //Serial.println("Button 2 longPress stop"); myservo.write(0); //Close the door mylcd.clear(); mylcd.setCursor(0, 0); mylcd.print("close"); } // longPressStop2