Advertisement
Guest User

Alarm Pt.2

a guest
Apr 26th, 2014
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.72 KB | None | 0 0
  1. /* The LCD circuit:
  2.  * LCD pin 1 to ground
  3.  * LCD pin 2 to 5V
  4.  * LCD RS pin 4 to digital pin 12  
  5.  * LCD R/W pin 5 to ground
  6.  * LCD Enable pin 6 to digital pin 11
  7.  * LCD D4 pin 11 to digital pin 5
  8.  * LCD D5 pin 12 to digital pin 4
  9.  * LCD D6 pin 13 to digital pin 3
  10.  * LCD D7 pin 14 to digital pin 2
  11.  * LCD pin 15 to 5v with 220ohm resistor
  12.  * LCD pin 16 to ground
  13.  *
  14.  * 10K pot:
  15.  *   one end to +5V and the other to ground
  16.  *   wiper (middle pin) to LCD pin 3
  17.  */
  18.  
  19. #include <Password.h>
  20.  
  21. // include the library code:
  22. #include <LiquidCrystal.h>
  23.  
  24. // include the keypad code:
  25. #include <Keypad.h>
  26.  
  27. Password password = Password( "3570" );
  28.  
  29. const byte ROWS = 4; //four rows
  30. const byte COLS = 3; //three columns
  31. char keys[ROWS][COLS] = {
  32.   {'1','2','3'},
  33.   {'4','5','6'},
  34.   {'7','8','9'},
  35.   {'*','0','#'}
  36. };
  37. //  keypad1 > pin13
  38. //  keypad2 > pin10
  39. //  keypad3 > pin9
  40. //  keypad4 > pin8
  41. //  keypad5 > pin7
  42. //  keypad6 > pin6
  43. //  keypad7 > pin0
  44. byte rowPins[ROWS] = {10, 0, 6, 8}; //connect to the row pinouts of the keypad
  45. byte colPins[COLS] = {9, 13, 7}; //connect to the column pinouts of the keypad
  46.  
  47. Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  48.  
  49. // initialize the library with the numbers of the interface pins
  50. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  51.  
  52. void setup() {
  53.   // set up the LCD's number of columns and rows:
  54.   lcd.begin(16, 2);
  55.   keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  56.   keypad.setDebounceTime(100);  //less bounce is more responsive
  57.  
  58.   // Print a message to the LCD.
  59.   lcd.print("Enter code:");
  60. }
  61.  
  62. void loop() {
  63.   // set the cursor to column 0, line 1
  64.   // line 0 is the first row, line 1 is the second row
  65.   lcd.setCursor(0, 1);
  66.  
  67.   keypad.getKey();
  68.  
  69. //  char key = keypad.getKey();
  70. //  if (key != NO_KEY){
  71. //      lcd.print(key);    // print keypress to LCD
  72. //  }
  73. }
  74.  
  75. //
  76.  
  77. //take care of some special events
  78. void keypadEvent(KeypadEvent eKey){
  79.   switch (keypad.getState()){
  80.       case PRESSED:
  81.       lcd.print(eKey);
  82.     switch (eKey){
  83.       case '#': guessPassword(); break;  // # is the 'enter' key
  84.       default:
  85.       password.append(eKey);
  86.     }
  87.   }  
  88. }
  89.  
  90. void guessPassword(){
  91.   if (password.evaluate()){
  92.     lcd.clear();
  93.     lcd.print("VALID PASSWORD"); //
  94.     password.reset(); //resets password after correct entry
  95.     delay(2000);
  96.     lcd.clear();
  97.     lcd.print("Welcome");
  98.     delay(3000);
  99.     lcd.clear();
  100.     lcd.setCursor(0, 0);
  101.     lcd.print("Enter code:");
  102.   }
  103.   else{
  104.     lcd.clear();
  105.     lcd.print("INVALID PASSWORD ");
  106.     password.reset(); //resets password after INCORRECT entry
  107.     delay(2000);
  108.     lcd.clear();
  109.     lcd.setCursor(0, 0);
  110.     lcd.print("Enter code:");
  111.   }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement