#include <Keypad.h>
#include <Servo.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET -1
#define screen_reset 0x3C
#define screen_width 128
#define screen_height 64
Adafruit_SSD1306 oled(screen_width, screen_height, &Wire, OLED_RESET);
Servo myservo;
int pos=0;
const byte ROWS = 4;
const byte COLS = 4;
char Keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = { 9, 8, 7, 6 };
byte colPins[COLS] = { 5, 4, 3, 2 };
Keypad customKeypad = Keypad( makeKeymap(Keys), rowPins, colPins, ROWS, COLS);
const String password_1 = "123ABC";
String input_password;
void setup() {
input_password.reserve(32);
Serial.begin(9600);
myservo.attach(10);
myservo.write(0);
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
delay(2000);
oled.clearDisplay();
oled.setTextSize(1.99);
oled.setTextColor(WHITE);
oled.setCursor(30, 20);
oled.println("password");
oled.display();
}
void loop() {
char key=customKeypad.getKey();
if(key){
if(key=='*'){
input_password="";
}else if(key=='#'){
if(input_password==password_1){
myservo.write(90);
Serial.println("berhasil");
oled.clearDisplay();
oled.setTextSize(1.99);
oled.setTextColor(WHITE);
oled.setCursor(30, 20);
oled.println("benar");
oled.display();
delay(10000);
myservo.write(0);
input_password="";
}
else{
Serial.println("gagal");
oled.clearDisplay();
oled.setTextSize(1.99);
oled.setTextColor(WHITE);
oled.setCursor(30, 20);
oled.println("gagal");
oled.display();
myservo.write(0);
input_password="";
}
}else{
input_password += key;
}
Serial.println(input_password);
}
}