Guest User

Untitled

a guest
Nov 14th, 2014
14,067
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Password.h>
  2. #include <Keypad.h>
  3. #include <LiquidCrystal.h>
  4.  
  5. Password password = Password("1*5#3");  // password
  6. int dlugosc = 5;                // length of the password
  7.  
  8. LiquidCrystal lcd(A0, A1, A5, A4, A3, A2);
  9.  
  10. int ledRed = 11;
  11. int ledGreen = 12;
  12. int buzzer = 13;
  13.  
  14. int ilosc; // number of clicks
  15.  
  16. const byte ROWS = 4; // rows
  17. const byte COLS = 3; // cols
  18.  
  19. char keys[ROWS][COLS] =
  20. {
  21.   {'1','2','3'},
  22.   {'4','5','6'},
  23.   {'7','8','9'},
  24.   {'*','0','#'}
  25. };
  26.  
  27. byte rowPins[ROWS] = {2,3,4,5};
  28. byte colPins[COLS] = {6,7,8};
  29.  
  30. Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  31.  
  32. void setup()
  33. {
  34.   Serial.begin(9600);
  35.   keypad.addEventListener(keypadEvent);  
  36.   pinMode(ledRed, OUTPUT);  
  37.   pinMode(ledGreen, OUTPUT);
  38.   pinMode(buzzer, OUTPUT);
  39.  
  40.   digitalWrite(ledRed, HIGH);
  41.   digitalWrite(ledGreen, LOW);
  42.  
  43.   lcd.begin(16, 2);
  44.  
  45.   lcd.setCursor(1,0);
  46.   lcd.print("  :Welcome:");
  47.   lcd.setCursor(0,1);
  48.   lcd.print("PLEASE ENTER PIN");
  49. }
  50.  
  51. void loop()
  52. {
  53.   keypad.getKey();
  54. }
  55. void keypadEvent(KeypadEvent eKey)
  56. {
  57.   switch (keypad.getState())
  58.   {
  59.     case PRESSED:
  60.    
  61. int i;
  62. for( i = 1; i <= 1; i++ )
  63. {
  64.   digitalWrite(buzzer, HIGH);  
  65.   delay(50);            
  66.   digitalWrite(buzzer, LOW);  
  67.   delay(50);      
  68. }    
  69.  
  70. Serial.print("Pressed: ");
  71. Serial.println(eKey);
  72.  
  73. switch (eKey)
  74. {
  75. /*
  76. case '#':
  77. break;
  78.  
  79. case '*':
  80. break;
  81. */
  82.  
  83. default:
  84. ilosc=ilosc+1;
  85. password.append(eKey);
  86. }
  87. //Serial.println(ilosc);
  88.  
  89. if(ilosc == 1)
  90. {
  91. lcd.clear();
  92. lcd.setCursor(1,0);
  93. lcd.print("   < PIN >");
  94. lcd.setCursor(0,1);
  95. lcd.print("*_");
  96. }
  97. if(ilosc == 2)
  98. {
  99. lcd.clear();
  100. lcd.setCursor(1,0);
  101. lcd.print("   < PIN >");
  102. lcd.setCursor(0,1);
  103. lcd.print("**_");
  104. }
  105. if(ilosc == 3)
  106. {
  107. lcd.clear();
  108. lcd.setCursor(1,0);
  109. lcd.print("   < PIN >");
  110. lcd.setCursor(0,1);
  111. lcd.print("***_");
  112. }
  113. if(ilosc == 4)
  114. {
  115. lcd.clear();
  116. lcd.setCursor(1,0);
  117. lcd.print("   < PIN >");
  118. lcd.setCursor(0,1);
  119. lcd.print("****_");
  120. }
  121. if(ilosc == 5)
  122. {
  123. lcd.clear();
  124. lcd.setCursor(1,0);
  125. lcd.print("   < PIN >");
  126. lcd.setCursor(0,1);
  127. lcd.print("*****_");
  128. }
  129. if(ilosc == 6)
  130. {
  131. lcd.clear();
  132. lcd.setCursor(1,0);
  133. lcd.print("   < PIN >");
  134. lcd.setCursor(0,1);
  135. lcd.print("******_");
  136. }
  137. if(ilosc == 7)
  138. {
  139. lcd.clear();
  140. lcd.setCursor(1,0);
  141. lcd.print("   < PIN >");
  142. lcd.setCursor(0,1);
  143. lcd.print("*******_");
  144. }
  145. if(ilosc == 8)
  146. {
  147. lcd.clear();
  148. lcd.setCursor(1,0);
  149. lcd.print("   < PIN >");
  150. lcd.setCursor(0,1);
  151. lcd.print("********");
  152. }
  153.  
  154. if(ilosc == dlugosc)
  155. {
  156. delay(250);
  157. checkPassword();
  158. ilosc = 0;
  159. }
  160. }
  161. }
  162.  
  163. void checkPassword()
  164. {
  165.   if (password.evaluate())
  166.   {
  167. int i;
  168. for( i = 1; i <= 2; i++ )
  169. {
  170.   digitalWrite(buzzer, HIGH);  
  171.   delay(70);            
  172.   digitalWrite(buzzer, LOW);  
  173.   delay(70);      
  174. }    
  175.     ilosc = 0;
  176.  
  177.     Serial.println("Success");    
  178.  
  179.     digitalWrite(ledRed, LOW);
  180.     digitalWrite(ledGreen, HIGH);
  181.  
  182.     lcd.clear();
  183.     lcd.setCursor(0,1);
  184.     lcd.print(" << SUCCESS >>");    
  185.  }  
  186.   else  
  187.   {
  188. int i;
  189. for( i = 1; i <= 1; i++ )
  190. {
  191.   digitalWrite(buzzer, HIGH);  
  192.   delay(200);            
  193.   digitalWrite(buzzer, LOW);  
  194.   delay(200);      
  195. }  
  196.     ilosc = 0;  
  197.     password.reset();
  198.  
  199.     Serial.println("Wrong");
  200.  
  201.     digitalWrite(ledGreen, LOW);
  202.     digitalWrite(ledRed, HIGH);    
  203.              
  204.     lcd.clear();
  205.     lcd.setCursor(0,1);
  206.     lcd.print("  << WRONG >>");
  207.     delay(2000);
  208.    
  209.     lcd.clear();
  210.     lcd.setCursor(1,0);
  211.     lcd.print("  :Welcome:");
  212.     lcd.setCursor(0,1);
  213.     lcd.print("PLEASE ENTER PIN");    
  214.   }
  215. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×