Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include <Keypad.h>
  2.  
  3. #define RED 10
  4. #define BLUE 11
  5. #define GREEN 12
  6.  
  7. const byte ROWS = 4; //four rows
  8. const byte COLS = 4; //four columns
  9. //define the cymbols on the buttons of the keypads
  10. char hexaKeys[ROWS][COLS] = {
  11. {'1','2','3','A'},
  12. {'4','5','6','B'},
  13. {'7','8','9','C'},
  14. {'*','0','#','D'}
  15. };
  16.  
  17. char password[] = { '1', '2', '3', '4'};
  18. bool startRed = false;
  19. bool isPass = false;
  20. byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
  21. byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
  22.  
  23. //initialize an instance of class NewKeypad
  24. Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
  25.  
  26. void setup(){
  27. pinMode(RED,OUTPUT);
  28. pinMode(GREEN, OUTPUT);
  29. pinMode(BLUE, OUTPUT);
  30. digitalWrite(RED,HIGH);
  31. digitalWrite(GREEN,LOW);
  32. digitalWrite(BLUE,LOW);
  33. Serial.begin(9600);
  34. }
  35.  
  36. int redValue;
  37. int greenValue;
  38. int blueValue;
  39.  
  40. void loop(){
  41. if (startRed = false) {
  42. Serial.println("Paina *-nappainta ja syota salasana.");
  43. analogWrite(RED, 255);
  44. startRed = true;
  45. }
  46.  
  47. char customKey = customKeypad.getKey();
  48.  
  49. if (customKey == '*')
  50. {
  51.  
  52. analogWrite(GREEN, 0);
  53. analogWrite(RED, 0);
  54. analogWrite(BLUE, 255);
  55.  
  56. char customKey2 = customKeypad.getKey();
  57. int i = 0;
  58. bool rr = false;
  59.  
  60. while (rr == false)
  61. {
  62. customKey2 = customKeypad.getKey();
  63.  
  64. if (customKey2 != password[i])
  65. {
  66. if (!customKey2 == NO_KEY)
  67. {
  68. analogWrite(BLUE, 0);
  69. Serial.println("\nVirheellinen salasana!!");
  70. break;
  71. }
  72. }
  73.  
  74. else
  75. {
  76. Serial.print('*');
  77. if (i == 3)
  78. {
  79. analogWrite(BLUE, 0);
  80. analogWrite(GREEN, 255);
  81. analogWrite(RED, 0);
  82. Serial.println(" Salasana oikein!");
  83. delay(5000);
  84. rr = true;
  85. }
  86. i++;
  87. }
  88. }
  89. analogWrite(GREEN, 0);
  90. analogWrite(RED, 255);
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement