Advertisement
neo7bf

two-pass-two-exits

Feb 14th, 2023 (edited)
1,059
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.49 KB | Source Code | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3. #include <Keypad.h>
  4. #define Password_Length 8 // Inserire la lunghezza della password
  5. //se la password è lunga 7 caratteri inserire 8
  6. //se la password è lunga 8 caratteri inserire 9 ecc..
  7. int signalPin = 12;   // Pin su cui è collegato il relè
  8. //TODO: creare signalPin2
  9. char Data[Password_Length];
  10. char Master[Password_Length] = "1234567";   //Modifica la password
  11. //TODO: creare Master2
  12. byte data_count = 0, master_count = 0;
  13. bool Pass_is_good;
  14. char customKey;
  15. const byte ROWS = 4;
  16. const byte COLS = 3;
  17. char hexaKeys[ROWS][COLS] = {
  18.   {'1', '2', '3'},
  19.   {'4', '5', '6'},
  20.   {'7', '8', '9'},
  21.   {'*', '0', '#'}
  22. };
  23. byte rowPins[ROWS] = {9, 8, 7, 6};
  24. byte colPins[COLS] = {5, 4, 3};
  25. Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
  26. // set the LCD address to "0x27"(or "0x3f") for a 16 chars and 2 line display
  27. // set the LCD address to "0x3f"(or "0x27") for a 16 chars and 2 line display
  28. LiquidCrystal_I2C lcd(0x3f, 16, 2);
  29.  
  30. void setup(){
  31.   lcd.init();
  32.   lcd.backlight();
  33.   pinMode(signalPin, OUTPUT);
  34.   digitalWrite(signalPin, HIGH);
  35. //TODO: gestire signalPin2
  36. }
  37.  
  38. //Questa funzione "loop" viene chiamata ciclicamente.
  39. //la lettura della password avviene carattere per carattere e solo quando
  40. //raggiunge la lunghezza giusta viene confrontata con quella interna.
  41.  
  42. //Ti serve di leggere prima l'uscita e dopo la password
  43. //quindi ti serve una variabile d'appoggio come customKey, diciamo customKey2
  44. //che conterrà l'uscita
  45. void loop(){
  46.   lcd.setCursor(0,0);
  47.  
  48. //leggere in customKey2 l'uscita scelta se non è stata scelta
  49.   if(!customKey2) {
  50.     lcd.print(" QUALE USCITA...");
  51.     customKey2 = customKeypad.getKey();
  52.     return;
  53.   }
  54.  
  55.   lcd.print("  PASSWORD...");
  56.   customKey = customKeypad.getKey();
  57.   if (customKey){
  58.     Data[data_count] = customKey;
  59.     lcd.setCursor(data_count,1);
  60.     lcd.print(Data[data_count]);
  61.     data_count++;
  62.   }
  63.   if(data_count == Password_Length-1){
  64.     lcd.clear();
  65.     if(customKey2 == '0' && !strcmp(Data, Master)){
  66.       lcd.print(" Pass Corretta");
  67.       digitalWrite(signalPin, LOW);
  68.       delay(1500);
  69.       digitalWrite(signalPin, HIGH);
  70.     }
  71.     if(customKey2 == '1' && !strcmp(Data, Master2)){
  72.         //TODO: gestire signalPin2 come sopra
  73.     }
  74.     else{
  75.       lcd.print("Pass Errata");
  76.       delay(3000);
  77.     }
  78.     lcd.clear();
  79.     clearData();  
  80.  }
  81. }
  82. void clearData(){
  83.   while(data_count !=0){
  84.     Data[data_count--] = 0;
  85.   }
  86.   return;
  87. }
Tags: Arduino iot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement