Advertisement
Kanamex

Examen Sistemas Embebidos

Jun 23rd, 2021
1,424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1.  
  2. #include <Keypad.h>
  3. #include <LiquidCrystal.h>
  4.  
  5. const byte ROWS = 4; // Cuatro Filas
  6. const byte COLS = 4; // Cuatro Columnas
  7.  
  8. LiquidCrystal lcd(A0, A1, A2, A3, A4, 1); //Definimos los pines del LCD
  9. char X;
  10. char B[6];
  11. char C[6]= "0497#"; // CLAVE
  12. byte D = 0;
  13. int E = 0;
  14. int ledv = 13;
  15. int ledr = 12;
  16. int estado = 0;;
  17.  
  18.  
  19. // Definimos el Keymap
  20. char keys[ROWS][COLS] = {
  21.   {'1','2','3','A'},
  22.   {'4','5','6','B'},
  23.   {'7','8','9','C'},
  24.   {'*','0','#','D'}
  25. };
  26. byte rowPins[ROWS] = { 9,8,7,6 }; // Pines conectados al Arduino
  27. byte colPins[COLS] = { 5,4,3,2,}; // Pines conectados al Arduino
  28.  
  29. Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  30.  
  31.  
  32. void setup(){
  33.   lcd.begin(16, 2);
  34.   digitalWrite(ledv, LOW);
  35.   pinMode(13, OUTPUT);
  36.   pinMode(12, OUTPUT);
  37.   pinMode(A5,INPUT);
  38. }
  39. void loop(){
  40.  
  41.  
  42.   X = keypad.getKey();
  43.   if(X){
  44.     B[D]= X;
  45.     D ++;
  46.   }
  47.   if(D==0){
  48.     lcd.setCursor(0,0);
  49.     lcd.print( "Bloqueado" );
  50.   }
  51.   if(D==1){
  52.     lcd.setCursor(6,1);
  53.     lcd.print( "*---" );
  54.   }
  55.   if(D==2){
  56.     lcd.setCursor(6,1);
  57.     lcd.print( "**--" );
  58.   }
  59.   if(D==3){
  60.     lcd.setCursor(6,1);
  61.     lcd.print( "*-" );
  62.   }
  63.   if(D==4){
  64.     lcd.setCursor(6,1);
  65.     lcd.print( "**" );
  66.   }
  67.  if((D>=5) && (X =='#')){
  68.     if(!strcmp(B,C)){
  69.       lcd.setCursor(0,0);
  70.       lcd.print("Acceso concedido");
  71.       delay(1000);
  72.       digitalWrite(ledv, HIGH);
  73.       delay(1200);
  74.       digitalWrite(ledv, LOW);
  75.       lcd.clear();
  76.       lcd.setCursor(3,0);
  77.       lcd.print("1 Distancia");
  78.       lcd.setCursor(3,1);
  79.       lcd.print("2 Temperatura");
  80.      
  81.     }
  82.     else
  83.     {
  84.       lcd.setCursor(0,0);
  85.       lcd.print("Incorrecto");
  86.       delay(1000);
  87.       digitalWrite(ledr, HIGH);
  88.       delay(1200);
  89.       digitalWrite(ledr, LOW);
  90.       E++;
  91.       D=0;
  92.       lcd.setCursor(0,1);
  93.       lcd.print("             ");
  94.     }
  95.   }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement