   }
 }
 
+// update delay on lcd screen
+void drawDelaySetMenu(){
+  lcd.clear();
+  lcd.setCursor(0, 0);
+  if(inPreDelayMenu){
+    lcd.print("Pre: ");
+  } else if(inPostDelayMenu){
+    lcd.print("Post: ");
+  }
+  lcd.print(delayVal);
+  lcd.print(" mins");
+}
+
+// update delay value loop - check encoder, if change, update lcd with new val
+void updateDelayValLoop(){
+  encState eState = encoder.read();
+  if (eState == ENC_DEC) {
+    if (delayVal == 0) {
+      delayVal = MAX_DELAY_MINUTES - 1;
+    } else {
+      delayVal = (delayVal - 1);
+    }
+    drawDelaySetMenu();
+  } else if (eState == ENC_INC) {
+    delayVal = (delayVal + 1) % (MAX_DELAY_MINUTES);
+    drawDelaySetMenu();
+  }
+}
+
+// When button clicked, change delay value
+void updateDelaySettings(){
+
+  if(inPreDelayMenu){
+    delayVal = delay_time_before_sunrise;
+  } else if(inPostDelayMenu){
+    delayVal = delay_time_after_sunset;
+  }
+  drawDelaySetMenu();
+  while(!setDelayValue){
+    updateDelayValLoop();
+    menuButton.read();
+    if(menuButton.wasReleased()){
+      // TODO: set delay value in EEPROM
+      setDelayValue = true;
+    }
+  }
+}
+
+// For drawing main menu
 void drawPreDelayMenu(){
   lcd.clear();
   lcd.print("Set delay before");

    }
     Serial.print(".");
  }
  Serial.println();

  // send low to door close motor pin

  }
}

// TODO: make piezo beep..
void beep(int pitch, int duration){
  
}

// Alert user to press a button, otherwise the system will try to open/close the door to the proper position
void waitForUserResetOpen(){
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Door will ");
  if(isDayTime && hitBottom){
    lcd.print("open");
  } else if(!isDayTime && hitTop){
    lcd.print("close");
  }
  lcd.setCursor(0, 1);
  lcd.print("Unless press btn");
  
  DateTime stopTime = rtc.now();
  DateTime fixTime;
  if(isDayTime && hitBottom){
    fixTime = stopTime + TimeSpan(0, 0, 0, 40);
  } else if(!isDayTime && hitTop){
    fixTime = stopTime + TimeSpan(0, 0, 0, 30);
  }
  
  bool pausedForUser = false;
  
  // while warning time not run out and user hasn't intervened
  while(fixTime.unixtime() - rtc.now().unixtime() > 0 && !pausedForUser){
    menuButton.read();
    if(menuButton.wasReleased()){
      pausedForUser = true;
    }
    beep(100, 500);
  }

  // if user wants to operate on door or something.. Leave door open/close (for a fair while)
  if(pausedForUser){
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Keeping door ");
    lcd.setCursor(0, 1);
    if(isDayTime && hitBottom){
      lcd.print("open");
    } else if(!isDayTime && hitTop){
      lcd.print("close");
    }
    lcd.print("Press btn");

    // Calculate timeout - we can't pause indefinately just incase of user error!
    stopTime = rtc.now();
    bool timeOut = false;
    
    if(isDayTime && hitBottom){
      fixTime = stopTime + TimeSpan(0, 0, 50, 0);
    } else if(!isDayTime && hitTop){
      fixTime = stopTime + TimeSpan(0, 0, 30, 0);
    }

    // while waiting for user
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Waiting for user");
    lcd.setCursor(0, 1);
    lcd.print("intervention.");
    
    while(!timeOut && pausedForUser){
      menuButton.read();
      if(menuButton.wasReleased()){
        pausedForUser = false;
      }
      if(fixTime.unixtime() - rtc.now().unixtime() > 0){
        timeOut = true;
      }
    }

    // If user took way too long, we should carry on! (also could be some real-world issue, eg something knocked limit switch?)
    if(timeOut){
      beep(100, 500);
      beep(100, 500);
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Sorry! Have to");
      lcd.setCursor(0, 1);
      if(isDayTime && hitBottom){
        lcd.print("open");
      } else if(!isDayTime && hitTop){
        lcd.print("close");
      }
      lcd.print(" Door.");
    } else {
      lcd.clear();
      lcd.setCursor(0, 0);
      if(isDayTime && hitBottom){
        lcd.print("Opening");
      } else if(!isDayTime && hitTop){
        lcd.print("Closing");
      }
      lcd.print(" door");
    }

    // finally, open or close the door
    if(isDayTime && hitBottom){
      openDoor();
    } else if(!isDayTime && hitTop){
      closeDoor();
    }
    
  }
  
}

// check limit switches - if door is open when it should be closed
void checkLimitSwitches(){
  // If daytime, only check if door has been manually or accidentally closed
  if(isDayTime){
    if(hitBottom){
      waitForUserResetOpen();
    }
    // if down switch pressed and day time
    if(digitalRead(PIN_LIMSW_DN) == HIGH){
      hitBottom = true;
    }
  } else {
    if(hitTop){
      waitForUserResetOpen();
    }
    // if up switch is pressed at day time
    if(digitalRead(PIN_LIMSW_DN) == HIGH){
      hitBottom = true;
    }
  }
}

void checkTime(){
