#include<stdio.h>
#include <RTClib.h>
RTC_DS1307 rtc;
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <ESP32Servo.h>
Servo myServo;
int pos = 0;
int servoPin = 26;
void setup() {
  // put your setup code here, to run once:
  Wire.begin();
  pinMode(2, OUTPUT );
  lcd.init();
  lcd.backlight();
  myServo.attach(26);
  if (!rtc.begin()){
  Serial.println("RTC Tidak Terhubung ");
  while(1);
  }
}

void loop() {
  DateTime now = rtc.now();
  int tahun = now.year();
  int bulan = now.month();
  int tanggal = now.day();
  int jam = now.hour();
  int menit = now.minute();
  int detik = now. second ();
  lcd.setCursor(0,0);
  lcd.println(String() + "tanggal:" + tanggal + "-" + bulan + "-" + tahun );
  lcd.setCursor(0,1);
  lcd.println(String() + "Waktu :" + jam + ":" + menit + ":" + detik );

  Serial.println(String() + "tanggal:" + tanggal + "-" + bulan + "-" + tahun );
  Serial.println(String() + "Waktu :" + jam + ":" + menit + ":" + detik );
  Serial.println();
  // put your main code here, to run repeatedly:
  delay(1000); // this speeds up the simulation
  if((detik == 10) ||(detik == 20) ||(detik == 40) ||(detik == 59) ){
    myServo.write(45);
    digitalWrite(2, HIGH);
    delay (1000);
    digitalWrite(2, LOW);

  }
    else {
          myServo.write(0);   // Move servo to 0 degrees
            }
}
GND5VSDASCLSQWRTCDS1307+