Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // importa libreria Keypad
- #include <Keypad.h>
- #include <LiquidCrystal_I2C.h>
- //SENSOR DE DISTANCIA
- LiquidCrystal_I2C lcd2(0x3F,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
- int echo = 13;
- int trigger = 12;
- int pulso;
- long tiempo;
- float distancia;
- // Crear el objeto lcd dirección 0x3F y 16
- // columnas x 2 filas
- LiquidCrystal_I2C lcd(0x27, 16, 2); //
- // define numero de filas
- const uint8_t ROWS = 4;
- // define numero de columnas
- const uint8_t COLS = 4;
- // define la distribucion de teclas
- char keys[ROWS][COLS] = {{'1', '2', '3', 'A'},
- {'4', '5', '6', 'B'},
- {'7', '8', '9', 'C'},
- {'*', '0', '#', 'D'}};
- // pines correspondientes a las filas
- uint8_t colPins[COLS] = {2, 15, 25, 26};
- // pines correspondientes a las columnas
- uint8_t rowPins[ROWS] = {19, 18, 5, 4};
- // crea objeto con los prametros creados previamente
- Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
- // Declaramos la variable que almacena el password
- // char pass[7]="ABCD45";
- String pass = "ABC123";
- String passwordIngresado;
- // Varible que alamacena la clave que se va ingresando
- char ingresapass[7];
- // Variable que define el numero de letra que se va ingresando
- int indice = 0;
- int pinLedVerde = 12;
- int pinLedRojo = 13;
- bool accesoHabilitado = false;
- int intento = 1;
- int contadorCaracteres = 0;
- int indicePantalla = 7;
- boolean echoController = true;
- boolean bienvenidoText = false;
- void setup() {
- //SENSOR DE MOVIMIENTO
- pinMode(echo,INPUT);
- pinMode(trigger,OUTPUT);
- lcd2.init(); // initialize the lcd
- lcd2.init();
- // PANTALLA LCD
- // Inicializar el LCD
- lcd.init();
- // Encender la luz de fondo.
- lcd.backlight();
- // KEYPAD
- pinMode(pinLedVerde, OUTPUT);
- pinMode(pinLedRojo, OUTPUT);
- Serial.begin(115200);
- // configuración del LCD
- lcd.begin(16, 2);
- // Mensaje inicial LCD
- lcd.print("Digite su clave:");
- lcd.setCursor(0, 1);
- lcd.print("* para ingresar");
- delay(500);
- // Desplazamiento del texto
- for (int pos = 0; pos < 13; pos++) {
- // izquierda
- lcd.scrollDisplayLeft();
- delay(100);
- }
- // desplazamiento a la derecha
- for (int pos = 0; pos < 26; pos++) {
- lcd.scrollDisplayRight();
- delay(100);
- }
- delay(500);
- lcd.clear();
- }
- void loop() {
- if (echoController){
- //SENSOR DE MOVIMIENTO
- digitalWrite(trigger,HIGH); //Para estabilizar el sensor
- delayMicroseconds(20);
- digitalWrite(trigger,LOW); // envío del pulso ultrasónico
- tiempo = pulseIn(echo,HIGH); //Función para medir la longitud del pulso entrante
- Serial.println(tiempo);
- //Obtener distancia en
- distancia= (0.0175*tiempo); //Fórmula para calcular la distancia en valor entero
- Serial.println(distancia);
- // lcd2.print(distancia);
- // lcd2.print("cm");
- lcd2.clear();
- if (distancia < 20) {
- echoController = false;
- bienvenidoText = true;
- }
- }
- else {
- if(bienvenidoText){
- lcd2.print("Bienvenido");
- bienvenidoText = false;
- delay(2000);
- lcd2.clear();
- }
- int conteo = 60;
- // obtiene tecla presionada y asigna a variable
- lcd.setCursor(0, 0);
- // print the number of second since reset:
- lcd.print("clave: ");
- char teclaIngresada = keypad.getKey();
- Serial.println(teclaIngresada);
- lcd.display();
- // CUANDO EL USUARIO INGRESA LA CONTRASEÑA
- // Se obtuvo correctamente un caracter
- if (teclaIngresada) {
- contadorCaracteres++;
- lcd.setCursor(indicePantalla, 0);
- if (contadorCaracteres <= 6) {
- lcd.print(teclaIngresada);
- passwordIngresado += teclaIngresada;
- if (passwordIngresado == pass) {
- accesoHabilitado = true;
- Serial.println("CONTRASENIA CORRECTA MI TERNA");
- } else {
- Serial.print("CONTRASEÑA DEFINIDA: ");
- Serial.println(pass);
- Serial.print("CONTRASEÑA INGRESADA: ");
- Serial.print(passwordIngresado);
- }
- }
- indicePantalla++;
- // Se presionó el botón de aceptar o 'ENTER'
- if (teclaIngresada == '*') {
- contadorCaracteres = 0;
- if (accesoHabilitado == true and !passwordIngresado.isEmpty()) {
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Acceso permitido");
- lcd.setCursor(0, 1);
- lcd.print("Bienvenido");
- digitalWrite(pinLedVerde, HIGH);
- delay(2000);
- digitalWrite(pinLedVerde, LOW);
- delay(500);
- delay(2000);
- lcd.clear();
- indicePantalla = 7;
- accesoHabilitado = false;
- passwordIngresado = "";
- contadorCaracteres = 0;
- //SENSOR DE MOVIMIENTO
- digitalWrite(trigger,HIGH); //Para estabilizar el sensor
- delayMicroseconds(20);
- digitalWrite(trigger,LOW); // envío del pulso ultrasónico
- tiempo = pulseIn(echo,HIGH); //Función para medir la longitud del pulso entrante
- Serial.println(tiempo);
- //Obtener distancia en
- distancia= (0.0175*tiempo); //Fórmula para calcular la distancia en valor entero
- Serial.println(distancia);
- // lcd2.print(distancia);
- // lcd2.print("cm");
- lcd2.clear();
- echoController = true;
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd2.print("Hasta Luego");
- lcd.print("Echo goodbye");
- lcd.clear();
- } else if (passwordIngresado.isEmpty()) {
- lcd.clear();
- lcd.setCursor(0, 1);
- lcd.print("Contrasena nula");
- digitalWrite(pinLedRojo, HIGH);
- delay(2000);
- digitalWrite(pinLedRojo, LOW);
- delay(500);
- lcd.setCursor(0, 0);
- indicePantalla = 7;
- accesoHabilitado = false;
- passwordIngresado = "";
- contadorCaracteres = 0;
- } else {
- // Mostramos el mensaje de acceso denegado
- lcd.clear();
- lcd.setCursor(0, 1);
- lcd.print("Acceso denegado");
- digitalWrite(pinLedRojo, HIGH);
- delay(2000);
- digitalWrite(pinLedRojo, LOW);
- delay(500);
- intento++;
- delay(1000);
- lcd.setCursor(0, 0);
- lcd.print("Intentos: ");
- lcd.setCursor(9, 0);
- lcd.print(intento);
- delay(1000);
- lcd.clear();
- indicePantalla = 7;
- accesoHabilitado = false;
- passwordIngresado = "";
- contadorCaracteres = 0;
- lcd.clear();
- }
- if (intento > 3) {
- while (conteo != 0) {
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Sistema");
- lcd.setCursor(0, 1);
- lcd.print("Bloqueado");
- lcd.setCursor(12, 1);
- lcd.print(conteo);
- delay(50);
- conteo--;
- }
- intento = 0;
- lcd.clear();
- }
- }
- if (teclaIngresada == '#') {
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Contrasena");
- lcd.setCursor(0, 1);
- lcd.print("reiniciada");
- digitalWrite(pinLedRojo, HIGH);
- delay(2000);
- digitalWrite(pinLedRojo, LOW);
- delay(500);
- lcd.clear();
- passwordIngresado = "";
- contadorCaracteres = 0;
- indicePantalla = 7;
- accesoHabilitado = false;
- lcd.clear();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement