Hi All,
I seem to be hitting a wall on how to do Time math on Arduino, and I'm hoping someone here might have some good ideas.
This is for my greenhouse sprinkler timer, to put it into context.
So I have an LCD display that shows the current time. That part is easy. The Time library works really well for that. I've added buttons to set the time, and all is good there.
Now I would like to calculate when the next time will be to run the sprinklers. And then I want to display that on the LCD under the current time.
For example, my display might look like:
Time 9:42a
Next 3:00p
I'm having trouble taking the current time and adding seconds or minutes to it without changing the current time. To change the current time we just need to use adjustTime(seconds). I would like to do something similar to a time_t variable.
I can compare two time_t structures by using the numberOfSeconds() function. To do that, time1 and time2 are converted to seconds and compared and that tells me what I need to know.
The problem I'm having is on how to create a time_t back from numberOfSeconds, in order to increment the time easily without having to increment seconds, check for overflow to minutes, then increment minutes and check overflow etc etc.
Here's what I have:
long secs;
time_t startTime;
time_t stopTime;
startTime = now();
secs = numberOfSeconds(startTime);
secs = secs + 90 * 60; // increment the time
// how to convert to stopTime?
I'm hoping someone has a super slick solution!
Thanks in advance,
-Nico