Guest User

Untitled

a guest
May 22nd, 2020
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #include <Keypad.h>
  3. #include "pitches.h"
  4.  
  5. #define BLUE 11
  6. #define GREEN 12
  7. #define RED 13
  8.  
  9. LiquidCrystal lcd(5, 6, 7, 8, 9, 10);
  10. const byte ROWS = 4; //four rows
  11. const byte COLS = 4; //four columns
  12. int sensor = 0;
  13. int pump = 23;
  14. //define the cymbols on the buttons of the keypads
  15. /*char hexaKeys[ROWS][COLS] = {
  16. {'1','2','3','A'},
  17. {'4','5','6','B'},
  18. {'7','8','9','C'},
  19. {'*','0','#','D'}
  20. };
  21. */
  22. char hexaKeys[ROWS][COLS] = {
  23. {'D','C','B','A'},
  24. {'#','9','6','3'},
  25. {'0','8','5','2'},
  26. {'*','7','4','1'}
  27. };
  28. byte rowPins[ROWS] = {53, 52, 51, 50}; //connect to the row pinouts of the keypad
  29. byte colPins[COLS] = {49, 48, 47, 46}; //connect to the column pinouts of the keypad
  30. int i;
  31. String code;
  32. boolean pas = false;
  33. String password = "1234";
  34. int redValue;
  35. int greenValue;
  36. int blueValue;
  37. //initialize an instance of class NewKeypad
  38. Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
  39. void setup() {
  40. // set up the LCD's number of columns and rows:
  41.  
  42. // pinMode (7, INPUT);
  43. // pinMode (A0, INPUT);
  44. //pinMode (pumpOn, OUTPUT);
  45. pinMode (sensor, INPUT);
  46. pinMode (pump, OUTPUT);
  47. digitalWrite(pump, LOW);
  48. pinMode(RED, OUTPUT);
  49. pinMode(GREEN, OUTPUT);
  50. pinMode(BLUE, OUTPUT);
  51. digitalWrite(RED, HIGH);
  52. digitalWrite(GREEN, LOW);
  53. digitalWrite(BLUE, LOW);
  54. Serial.begin(9600);
  55. i = 0;
  56. lcd.begin(16, 2);
  57. lcd.print("Password:");
  58. code = "";
  59. }
  60.  
  61. void loop() {
  62. char customKey = customKeypad.getKey();
  63. led(255, 0, 40);
  64.  
  65. if(!pas){
  66. Serial.println("test");
  67. if (customKey){
  68. if(customKey == 'A'){
  69.  
  70. tone(22, NOTE_C5, 400);
  71. if(code == password){
  72. tone(22, NOTE_B5, 600);
  73. tone(22, NOTE_C5, 600);
  74. led(0, 0, 255);
  75. lcd.clear();
  76. lcd.setCursor(0, 0);
  77. lcd.print("Zugriff");
  78. lcd.setCursor(0, 1);
  79. lcd.print("gewaehrt!");
  80. delay(2000);
  81. led(0, 0, 0);
  82.  
  83. lcd.clear();
  84. lcd.setCursor(0, 0);
  85. lcd.print("Code:");
  86. pas = true;
  87. i=0;
  88. code="";
  89. }else{
  90. code = "";
  91. i=0;
  92. lcd.clear();
  93. lcd.print("Falsches");
  94. lcd.setCursor(0, 1);
  95. lcd.print("Password");
  96. led(255, 0, 0);
  97. tone(22, NOTE_B5, 600);
  98. delay(2000);
  99. lcd.clear();
  100. lcd.print("Password:");
  101. }
  102. }else if(customKey == 'C'){
  103. if(i != 0){
  104. i--;
  105. tone(22, NOTE_C5, 400);
  106. lcd.setCursor(i, 1);
  107. lcd.print(" ");
  108. char copy[code.length()];
  109. code.toCharArray(copy, code.length());
  110. code = "";
  111. for(int z = 0; z<sizeof(copy)-1; z++){
  112. code = code+copy[z];
  113. }
  114. }
  115. }else if(customKey == 'B'){
  116.  
  117. if(i != 0){
  118. i = 0;
  119. tone(22, NOTE_C5, 400);
  120. char copy[code.length()];
  121. code.toCharArray(copy, code.length());
  122. code = "";
  123. for(int z = 0; z<sizeof(copy); z++){
  124. lcd.setCursor(z, 1);
  125. lcd.print(" ");
  126.  
  127. }
  128. }
  129.  
  130.  
  131. }else{
  132.  
  133. tone(22, NOTE_C5, 400);
  134. lcd.setCursor(i, 1);
  135. lcd.print("#");
  136. code = code+customKey;
  137. i++;
  138. }
  139.  
  140. }
  141. }else{
  142.  
  143. int prozent = 100- analogRead(sensor)/10.2;
  144. Serial.println(prozent);
  145. if(prozent <= 70){
  146. digitalWrite(pump, HIGH);
  147. Serial.println("motor an");
  148. delay(2000);
  149. Serial.println("motor aus");
  150. digitalWrite(pump, LOW);
  151. delay(2000);
  152. }
  153. if (customKey){
  154.  
  155. tone(22, NOTE_C5, 400);
  156. if(i!=0 && customKey == 'C'){
  157. i--;
  158. lcd.setCursor(i, 1);
  159. lcd.print(" ");
  160. char copy[code.length()];
  161. code.toCharArray(copy, code.length());
  162. code = "";
  163. for(int z = 0; z<sizeof(copy)-1; z++){
  164. code = code+copy[z];
  165. }
  166. }else if(customKey == 'D'){
  167. pas = false;
  168. lcd.clear();
  169. led(255, 0, 0);
  170. lcd.print("Abgemeldet!");
  171. delay(2000);
  172. lcd.clear();
  173. lcd.print("Password:");
  174. i=0;
  175. code="";
  176. }else{
  177.  
  178. lcd.setCursor(i, 1);
  179. lcd.print(customKey);
  180. code = code+customKey;
  181. i++;
  182. }
  183. }
  184.  
  185. }
  186.  
  187. /*int istTrocken = digitalRead(11); // Pin 11 auslesen -> in Variable istTrocken
  188. int feuchtigkeit = analogRead(A0); // Pin A0 auslesen -> in Variable feuchtigkeit
  189. Serial.print("istTrocken: "); // Variablenname für Übersichtlichkeit im Serial Monitor
  190. Serial.println(istTrocken); // Wert von "istTrocken" ausgeben
  191. Serial.print("feuchtigkeit: "); // Variablenname für Übersichtlichkeit im Serial Monitor
  192. Serial.println(feuchtigkeit);
  193. //delay(1000);
  194. /*int istTrocken = digitalRead(52);
  195. int feuchtigkeit = analogRead(A0);
  196. Serial.print("istTrocken: ");
  197. Serial.println(istTrocken);
  198. Serial.print("feuchtigkeit: ");
  199. Serial.println(feuchtigkeit);
  200. delay(1000);
  201. */
  202. }
  203.  
  204. void led(int red, int blue, int green){
  205. analogWrite(RED, red);
  206. analogWrite(GREEN, green);
  207. analogWrite(BLUE, blue);
  208. }
Add Comment
Please, Sign In to add comment