My doughter has trouble sleeping. She always comes tot he bed.. so I would like to build a visual countdown, that shows her how long it is till the end of the night. Usually she wakes up aroudn 5Pm. thats almost the end of the night..
I would like to display this with a digital ledstrip. the more lights are on and the longer the night lasts.
What I would need is the remaining seconds till 7am. I am able to get day of week, hours, minutes etc.. with the NTP client lib, but I would need to get the seconds till 7Am.. how can I do this?
You know the time NOW, you know if you are before midnight or after, you know how meny Seconds are in a minute, and an hour. Simple maths from that point.
// For this to work,
// you need variables hh, mi, ss to contain current hours, minutes, seconds
// calculate seconds since midnight
long secondsSinceMidnight = (hh * 3600L) + (mi * 60L) + ss;
// calculate the number of seconds to go
long secondsToGo = (7 * 3600L) - secondsSinceMidnight;
// As long as we restrict ourselves to times between 00:00 and 07:00,
// our secondsToGo calculation will be correct.
// However, for times in the evening, such as 20:00 or 23:00,
// the result will not be what we want. We need a fix for evening times.
// This fix will cause our countdown to restart 8 hours after the wake-up time.
// So, our countdown will start at 15:00, with 16 hours remaining.
// Fix for evening times:
if (secondsToGo < ((-8) * 3600L)) {
// add 24 hours worth of seconds
secondsToGo += (24 * 3600L);
}