//Koding RTC -------------------------------------->
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 rtc;

//Koding LCD --------------------------------------->
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

//Koding Servo --------------------------------------->
#include <ESP32Servo.h>
const int servoPin = 5;
Servo mekanik;

void setup(){
  Serial.begin(115200);

  //Koding Servo --------------------------------------->
  mekanik.attach(servoPin);
  mekanik.write(0);

  //Koding LCD --------------------------------------->
  lcd.init();
  lcd.backlight();
  lcd.clear();

  //Koding RTC -------------------------------------->
  Wire.begin();
  if(!rtc.begin()){
    Serial.println("RTC Tidak Terhubung");
    lcd.setCursor(0,0);
    lcd.print("RTC Tidak Konek");
    while (1);
  }

  lcd.clear();
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));


}

void loop(){

  //Koding RTC -------------------------------------->
  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();

  //Koding LCD --------------------------------------->
  lcd.setCursor(0,0);
  lcd.print(String() + "Tang.: " + tanggal + "-" + bulan + "-" + tahun);
  lcd.setCursor(0,1);
  lcd.print(String() + "Waktu: " + jam + ":" + menit + ":" + detik + "  ");

  Serial.println(String() + "Tanggal: " + tanggal + "-" + bulan + "-" + tahun);
  Serial.println(String() + "Waktu  : " + jam + ":" + menit + ":" + detik);
  Serial.println();

  //Jadwal Pagi ------------------------------------------------------->
  if( (jam == 6) && (menit == 30) && (detik == 1) ){
   kasihPakan();
  }

  //Jadwal Siang ------------------------------------------------------->
  if( (jam == 13) && (menit == 15) && (detik == 1) ){
   kasihPakan();
  }

  //Jadwal Sore ------------------------------------------------------->
  if( (jam == 17) && (menit == 45) && (detik == 1) ){
   kasihPakan();
  }



  delay(1000);
}

//Fungsi Kasih Pakan-------------------------------------------->
void kasihPakan(){
    lcd.clear();
    lcd.print("FEEDING TIME..");
    mekanik.write(180);
    delay(3000);
    mekanik.write(0);
    lcd.clear();
}
GND5VSDASCLSQWRTCDS1307+