#include <LiquidCrystal.h>

LiquidCrystal lcd(13, 12, 11, 10, 9, 8);


#define relay1 2
#define relay2 3
#define relay3 4
#define pot1 A0
#define pot2 A1
#define switchOnOff 7
int flag1 = 0;
int flag2 = 0;
int flag3 = 0;
int oldValue1 = 999;
int oldValue2 = 999;
unsigned long timeOn, timeOff;
void setup() {
  Serial.begin(115200);
  lcd.begin(16, 2);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(switchOnOff, INPUT_PULLUP);
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
  digitalWrite(relay3, HIGH);
  pinMode(pot1, INPUT);
  pinMode(pot2, INPUT);
  timeOn = millis();
  timeOff = millis();
}


bool switchOutput(int sw) {
  if (digitalRead(sw) == LOW) {
    delay(50);
    while (true){
      if (digitalRead(sw) == HIGH) {
        break;
      }
    }
    return true;
  }
  return false;
}

void loop() {
  int data1 = analogRead(pot1);
  int percentage1 = map(data1, 0, 1023, 1, 100);
  int data2 = analogRead(pot2);
  int percentage2 = map(data2, 0, 1023, 1, 100);
  // if (oldValue1 != percentage1) {
  //   lcd.clear();
  //   oldValue1 = percentage1;
  // }
  // if (oldValue2 != percentage2) {
  //   lcd.clear();
  //   oldValue2 = percentage1;
  // }
  lcd.setCursor(0, 0);
  lcd.print("On time|Off time");

    lcd.setCursor(0, 1);
  if (percentage1 < 100) {
    lcd.print("0");
  }
  if (percentage1 < 10) {
    lcd.print("0");
  }
  
  lcd.print(percentage1);
  lcd.print("s");


  lcd.setCursor(12, 1);
  if (percentage2 < 100) {
    lcd.print("0");
  }
  if (percentage2 < 10) {
    lcd.print("0");
  }
  lcd.print(percentage2);
  lcd.print("s");

  if (switchOutput(switchOnOff)) {
    timeOn = millis();
    flag2 = 1;
    if (flag1 == 0) {
      flag1 = 1;
    } else if (flag1 == 1) {
      flag1 = 0;
    }
  }
  if (flag1 == 1) {
    lcd.setCursor(6, 1);
    lcd.print("On..");
    if (flag2 == 1) {
      if ((millis() - timeOn) > (percentage1 * 1000) ) {
        timeOff = millis();
        flag2 = 0;
        flag3 = 1;
        digitalWrite(relay1, LOW);
        digitalWrite(relay2, LOW);
        digitalWrite(relay3, LOW);
      }
    }
    
    if (flag3 == 1) {
      if ((millis() - timeOff) > (percentage2 * 1000) ) {
        timeOn = millis();
        flag2 = 1;
        flag3 = 0;
        digitalWrite(relay1, HIGH);
        digitalWrite(relay2, HIGH);
        digitalWrite(relay3, HIGH);
      }
    }
  } else {
    lcd.setCursor(6, 1);
    lcd.print("Off.");
  }


}
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module