#include<Keypad.h> // Bibliotecas utilizadas
#include <ESP32Servo.h>
//#include<Servo.h> // biblioteca usada com o microcontrolador Arduino
#include <LiquidCrystal_I2C.h>
//#include<LiquidCrystal.h> // biblioteca usada com o microcontrolador Arduino
//LiquidCrystal lcd(A0,A1,A2,A3,A4,A5); // objeto criado lcd com o microcontrolador Arduino
LiquidCrystal_I2C lcd(0x27, 16,2);
Servo servo_motor; // servo-motor // objeto servo criado para ser controlado
const byte linhas=4;
const byte colunas=4;
char keys[linhas][colunas]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte pinoslinhas[linhas]={19,18,17,16}; // usar para as linhas do teclado no ESP32 os GPIOS: 19,18,17,16
byte pinoscolunas[colunas]={5,4,33,2}; //usar para as colunas do teclado no ESP32 os GPIOS: 5,4,33,2
Keypad teclado = Keypad(makeKeymap(keys), pinoslinhas, pinoscolunas,linhas,colunas);
char tecla;
char senha[4]; // 0 1 2 3
char senha_ok[4]="123";
byte index=0;
int led_verde=12;
int led_vermelho=13;
void setup(){
lcd.begin(16,2);
pinMode(led_verde,OUTPUT);
pinMode(led_vermelho,OUTPUT);
servo_motor.attach(14);
}
void loop(){
lcd.setCursor(0,0);
lcd.print("INSERIR SENHA:");
tecla=teclado.getKey();
delay(100);
if(tecla){
senha[index]=tecla; // 456
index++;
lcd.setCursor(0,1);
lcd.print(senha);
delay(100);
}
if(index==3){
if(!strcmp(senha,senha_ok)){//comparação das senhas 0 = false & 1=true
lcd.clear();
lcd.setCursor(0,1);
lcd.print("CORRETA");
digitalWrite(led_verde,HIGH);
servo_motor.write(0);
delay(5000);
servo_motor.write(90);
digitalWrite(led_verde,LOW);
index=0;
strcpy(senha," ");
lcd.clear();
}
else{
lcd.clear();
lcd.setCursor(0,1);
lcd.print("INCORRETA");
digitalWrite(led_vermelho,HIGH);
delay(2000);
digitalWrite(led_vermelho,LOW);
index=0;
strcpy(senha," ");
lcd.clear();
}
}
}