Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Password.h>
- #include <LiquidCrystal.h>
- Password password = Password( "1234" );
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- byte currentLength = 0;
- int led = 13;
- void setup(){
- pinMode(led, OUTPUT);
- Serial.begin(9600);
- Serial.println("Try to guess the password!");
- Serial.println("Reset with ! evaluate with ?");
- Serial.print("Enter password: ");
- lcd.begin(16, 2);
- lcd.print("Enter Password");
- }
- void loop(){
- if (Serial.available()){
- char input = Serial.read();
- switch (input){
- case '!': //reset password
- password.reset();
- currentLength = 0;
- lcd.clear();
- // lcd.setCursor(16, 2);
- lcd.print("Password Reset");
- Serial.println("Password is reset!");
- break;
- case '?': //evaluate password
- if (password.evaluate()){
- lcd.clear();
- lcd.print("Correct");
- //LED Flash
- Serial.println("\tYou guessed the correct password!");
- digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(1000); // wait for a second
- digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
- delay(1000);
- digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(1000); // wait for a second
- digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
- delay(1000);
- digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(1000); // wait for a second
- digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
- delay(1000);
- //Reset Password After Success
- password.reset();
- currentLength = 0;
- lcd.clear();
- delay(500);
- //Telling you it has been reset
- lcd.print("Password Reset");
- Serial.println("Password is reset!");
- delay(3000);
- lcd.clear();
- lcd.print("Enter Password");
- }
- else{
- lcd.clear();
- lcd.print("Incorrect");
- Serial.println("\tYou did not guess the correct password!");
- delay(3000);
- //Reset Password After Fail
- password.reset();
- currentLength = 0;
- lcd.clear();
- delay(500);
- //Telling you it has been reset
- lcd.print("Password Reset");
- Serial.println("Password is reset!");
- delay(5000);
- lcd.clear();
- lcd.print("Enter Password");
- }
- break;
- default: //append any keypress that is not a '!' nor a '?' to the currently guessed password.
- password << input;
- currentLength++;
- lcd.clear();
- lcd.print("Input: ");
- Serial.print("Enter password: ");
- for (byte i=0; i<currentLength; i++){
- lcd.print('*');
- Serial.print('*');
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment