#include <Servo.h>
Servo myservo;
int sudut;
int kondisi;
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void servo();
#define mer 52
#define k 51
#define h 50
#include <Keypad.h>
const int ROW_NUM = 4; //four rows
const int COLUMN_NUM = 4; //four columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'1','2','3', 'A'},
{'4','5','6', 'B'},
{'7','8','9', 'C'},
{'*','0','#', 'D'}
};
byte pin_rows[ROW_NUM] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {6, 7, 8, 9}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
void pw();
String password = "1234";
String mypassword;
int counter = 0;
void ngulangin();
#include <RTClib.h>
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
#include <TM1637Display.h>
#define CLK 23
#define DIO 25
TM1637Display display = TM1637Display(CLK, DIO);
void setup() {
Serial.begin(9600);
myservo.attach(53);
lcd.init();
lcd.backlight();
pinMode(mer,OUTPUT);
pinMode(k,OUTPUT);
pinMode(h,OUTPUT);
if (! rtc.begin())
{
Serial.println("Couldn't find RTC");
Serial.flush();
while (1);
}
}
void loop() {
while(kondisi == 0)
{
lcd.clear();
digitalWrite(mer, HIGH);
digitalWrite(k, HIGH);
digitalWrite(h, HIGH);
delay(500);
digitalWrite(mer, LOW);
digitalWrite(k,LOW);
digitalWrite(h, LOW);
delay(500);
digitalWrite(mer, HIGH);
digitalWrite(k, HIGH);
digitalWrite(h, HIGH);
delay(500);
digitalWrite(mer, LOW);
digitalWrite(k,LOW);
digitalWrite(h, LOW);
delay(500);
digitalWrite(mer, HIGH);
digitalWrite(k, HIGH);
digitalWrite(h, HIGH);
delay(500);
digitalWrite(mer, LOW);
digitalWrite(k,LOW);
digitalWrite(h, LOW);
DateTime now = rtc.now();
display.setBrightness(7);
int displaytime = (now.hour() * 100) + now.minute();
display.showNumberDecEx(displaytime, 0b11100000, true);
Serial.print("Date & Time: ");
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.println(now.second(), DEC);
delay(1);
lcd.setCursor(1, 0);
lcd.print("Hai,Masukan PW");
kondisi = 1;
}
while(kondisi == 1)
{
char key = keypad.getKey();
if (key){
Serial.println(key);
counter = counter + 1;
lcd.setCursor(counter, 1);
lcd.print("*");
}
if (key == '1')
{
mypassword = mypassword + 1;
}
if (key == '2')
{
mypassword = mypassword + 2;
}
if (key == '3')
{
mypassword = mypassword + 3;
}
if (key == '4')
{
mypassword = mypassword + 4;
}
if (key == '5')
{
mypassword = mypassword + 5;
}
if (key == '6')
{
mypassword = mypassword + 6;
}
if (key == '7')
{
mypassword = mypassword + 7;
}
if (key == '8')
{
mypassword = mypassword + 8;
}
if (key == '9')
{
mypassword = mypassword + 9;
}
if (key == '0')
{
mypassword = mypassword + 0;
}
if (key == '#')
{
if ( password == mypassword )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("pw Benar");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Open Door...");
delay(500);
myservo.write(180);
}
else
{
lcd.clear();
mypassword = "0";
Serial.println(mypassword);
lcd.setCursor(0, 0);
lcd.print("pw Salah");
delay(500);
kondisi = 0;
}
}
}
while (kondisi == 2)
{
lcd.clear();
}
}
void servo()
{
sudut = analogRead(A0);
sudut = map(sudut, 0, 1023, 0, 180);
myservo.write(sudut);
delay(15);
}