Hi there, it's my first time to post here and I look forward to become active
So I am building a countdown timer using an Arduino Uno, 16x2 blue LCD and a RTC DS3231.
My concept is to take the time now (using RTC), and then get the difference between now and the user's input to be able to display a nice HH:MM:SS:MSC formated remaing time.
So I am able to get everything working except for when the endTime is in the next day.
For example at 19:35:00:000 (now) the countdown tells me that there is 5:25:00:000 till the clock ticks 1:00:00:000
But in the case when I input 2:00:00:000 as the deadline, the countdown displays 00:25:00:000.
BUT WHY IS IT WORKING FOR SOME HOURS AND FOR OTHERS NOT?
I've been working on this issue for the past 3 days and I couldn't find the solution.
Any help? please? Any thing would be greatly appreciated
Here is the part of the code where difference gets calculated
int displayCountdown(){
 // if (time's up)
 // display 00.00.00.000 and lcd.print("Time's up."); at lcd.setCursor(3,1);
 //else
 // display running time and animation()
 DateTime now = rtc.now();
 hourNow = now.hour();
 minuteNow = now.minute();
 secondNow = now.second();
 int minutes = (hourNow*60) + minuteNow;
 int secondsStart = (minutes*60) + secondNow; //start timer here
 int minuteEnd = (hour*60) + minute;
 int secondsEnd = (minuteEnd*60) + second;  //end timer here
 //difference is the remaining time
 //if difference <0 => end time is in the next day
 if(secondsEnd - secondsStart < 0){
   int temp = abs(secondsEnd - secondsStart);
   deltaTimeSeconds = 86400 - (temp);
  }else if(secondsEnd - secondsStart == 0){
   deltaTimeSeconds = 86400;
  }else{
   deltaTimeSeconds = secondsEnd - secondsStart;
  }
 if(deltaTimeSeconds !=0){
  int convertedSecond = (deltaTimeSeconds % 60);
  int convertedMinute = (deltaTimeSeconds % 3600) / 60;
  int convertedHour = (deltaTimeSeconds % 86400) / 3600;
  int convertedMillisecond = 0;
And attached is the full 444-lined code:
OS_Countdown.ino (10.3 KB)