Guest User

Serial Monitor Passcode

a guest
Oct 25th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 KB | None | 0 0
  1. #include <Password.h>
  2. #include <LiquidCrystal.h>
  3.  
  4. Password password = Password( "1234" );
  5. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  6. byte currentLength = 0;
  7.  
  8. int led = 13;
  9.  
  10. void setup(){
  11.   pinMode(led, OUTPUT);
  12.   Serial.begin(9600);
  13.   Serial.println("Try to guess the password!");
  14.   Serial.println("Reset with ! evaluate with ?");
  15.   Serial.print("Enter password: ");
  16.   lcd.begin(16, 2);
  17.   lcd.print("Enter Password");
  18. }
  19.  
  20. void loop(){
  21.   if (Serial.available()){
  22.     char input = Serial.read();
  23.     switch (input){
  24.     case '!': //reset password
  25.       password.reset();
  26.       currentLength = 0;
  27.       lcd.clear();
  28.       // lcd.setCursor(16, 2);
  29.       lcd.print("Password Reset");
  30.       Serial.println("Password is reset!");
  31.       break;
  32.     case '?': //evaluate password
  33.       if (password.evaluate()){
  34.         lcd.clear();
  35.         lcd.print("Correct");
  36.         //LED Flash
  37.         Serial.println("\tYou guessed the correct password!");
  38.         digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  39.         delay(1000);               // wait for a second
  40.         digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  41.         delay(1000);    
  42.         digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  43.         delay(1000);               // wait for a second
  44.         digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  45.         delay(1000);    
  46.         digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  47.         delay(1000);               // wait for a second
  48.         digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  49.         delay(1000);  
  50.         //Reset Password After Success
  51.         password.reset();
  52.         currentLength = 0;
  53.         lcd.clear();
  54.         delay(500);
  55.         //Telling you it has been reset
  56.         lcd.print("Password Reset");
  57.         Serial.println("Password is reset!");
  58.         delay(3000);
  59.         lcd.clear();
  60.         lcd.print("Enter Password");
  61.  
  62.       }
  63.       else{
  64.         lcd.clear();
  65.         lcd.print("Incorrect");
  66.         Serial.println("\tYou did not guess the correct password!");
  67.         delay(3000);  
  68.         //Reset Password After Fail
  69.         password.reset();
  70.         currentLength = 0;
  71.         lcd.clear();
  72.         delay(500);
  73.         //Telling you it has been reset
  74.         lcd.print("Password Reset");
  75.         Serial.println("Password is reset!");
  76.         delay(5000);
  77.         lcd.clear();
  78.         lcd.print("Enter Password");
  79.       }
  80.       break;  
  81.     default: //append any keypress that is not a '!' nor a '?' to the currently guessed password.
  82.       password << input;
  83.       currentLength++;
  84.  
  85.       lcd.clear();
  86.       lcd.print("Input: ");
  87.       Serial.print("Enter password: ");
  88.       for (byte i=0; i<currentLength; i++){
  89.         lcd.print('*');
  90.         Serial.print('*');
  91.       }
  92.     }
  93.   }
  94. }
Add Comment
Please, Sign In to add comment