//#include <Wire.h>
#include "LiquidCrystal_I2C.h"
#include "RTClib.h"
//#include <Servo.h> (perintah ini buat di arduino uno r3)
#include <ESP32Servo.h>
#include <OneWire.h>
#include <DallasTemperature.h>


#define SENSOR_PIN 33
//const int oneWireBus = 33;  
OneWire oneWire(SENSOR_PIN);
DallasTemperature sensors(&oneWire);
float tempC; // temperature in Celsius
float tempF; // temperature in Fahrenheit
Servo myservo;
RTC_DS1307 rtc;

LiquidCrystal_I2C lcd(0x27, 16, 2);


void setup() {
  myservo.attach(13); 
  myservo.write(0);
  Serial.begin(115200);
  //Wire.begin();
  sensors.begin();

  if (! rtc.begin()) 
  {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }

  lcd.init();
  lcd.backlight();
  lcd.print("yes");

}

void loop() {
  sensors.setResolution(12);
  sensors.requestTemperatures();//menghasilkan datab20 seosnor suhu 18
  tempC = sensors.getTempCByIndex(0);  // read temperature in Celsius
  tempF = tempC * 9 / 5 + 32; // convert Celsius to Fahrenheit

  //Serial.print(sensors.getTempCByIndex(0));
  //Serial.println(" C");
  //Celcius=sensors.getTempCByIndex(0);  
  //Fahrenheit=sensors.toFahrenheit(Celcius);  
  //Serial.print(Celcius);
  //Serial.print(Fahrenheit);

  DateTime now = rtc.now();
  Serial.print(now.hour());
  Serial.print(":");
  Serial.print(now.minute());
  Serial.print(":");
  Serial.print(now.second());
  Serial.println(" ");

  
  lcd.setCursor( 0,0);
  lcd.print(now.hour());
  lcd.print(":");
  lcd.print(now.minute());
  lcd.print(":");
  lcd.print(now.second());
  lcd.println(" ");

  lcd.setCursor( 0,1);
  lcd.print(tempC);
  lcd.print(tempF);
 
  if ((now.hour() == 18 and now.minute() == 12 and now.second() == 0)) {
  myservo.write(90);
  delay(3000);
  myservo.write(0);}
  //delay(3000);}
 
  
}
GND5VSDASCLSQWRTCDS1307+