#include <Wire.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>

Servo myservo;          // Create a servo object
LiquidCrystal_I2C lcd(0x27, 16, 2);  // I2C address 0x27, 16 columns and 2 rows

int minPotPin = A0;      // Analog pin for the minute potentiometer
int secPotPin = A1;      // Analog pin for the second potentiometer

const int ledPin = 13;   // LED connected to digital pin 13

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

  myservo.attach(9);   // Attaches the servo on pin 9
  pinMode(ledPin, OUTPUT);  // Set the LED pin as an output

  lcd.begin(16, 2);    // Initialize the LCD
  lcd.backlight();     // Turn on the backlight

  myservo.write(0);
}

void loop() {
  int setMin = map(analogRead(minPotPin), 0, 1023, 0, 59);    // Map the minute potentiometer value to minutes (0 to 59)
  int setSec = map(analogRead(secPotPin), 0, 1023, 0, 59);    // Map the second potentiometer value to seconds (0 to 59)

  int setMillis = (setMin * 60 + setSec) * 1000;  // Convert minutes and seconds to milliseconds

  int currentTime = millis();  // Get the current time

  // Update LCD display
  // lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Set Time: ");
  lcd.print(setMin);
  lcd.print(":");
  lcd.print(setSec);
  lcd.setCursor(0, 1);
  lcd.print("Time: ");
  lcd.print(currentTime / 60000);  // Convert milliseconds to minutes
  lcd.print(":");
  lcd.print((currentTime / 1000) % 60);  // Get the remaining seconds

  if (currentTime % setMillis < 1000 * 5) {  // Open the servo for 5 seconds
    myservo.write(180);  // Set the servo to position 180 (open)
  } else {
    myservo.write(0);    // Set the servo back to position 0 (close)
  }

  // Blink the LED every second
  if (currentTime % 1000 == 0) {
    digitalWrite(ledPin, HIGH);
    delay(100);  // Small delay for LED to be visible
    digitalWrite(ledPin, LOW);
  }
}
$abcdeabcde151015202530fghijfghij
GND5VSDASCLSQWRTCDS1307+