I suggest you look at the other thread he started, here:
tl;dr: He wants to calculate the sun's elevation and azimuth. He already has a sketch to do that, but it requires manual input of the day of year and time of day in a specific format. He is trying to get the date and time information from the DS3231 so that he does not need to input it manually.
But make the time variable global, and call it when needed like
DateTime now;
void lool()
{
now = rtc.now();
static int lastPrinted = -1;
if (lastPrinted != now.second) {
printTime();
lastPrinted = now.second;
}
// rest of the loop is freely running
}
leaving yourself a free running loop() with > 99 of the processor's resources available for eveything else you wanna do.
The check for the need to print could be placed in the printTime() function, that's just a style or personal preference. I tend to call things and let them decide if it is time to do anything, or if other conditions mean they shoukd.
I have the impression that @petercl14's obsession with getting this on one line of code is borne of some misconception that to appear on one line of a display the code for doing must be all on one line. I don't remember if this has been vigorously dismissed as nonsense, certainly total and maybe even dangerous, and no time to do myself.
I would venture to guess that @petercl14's goal is something other than displaying the time.
I would also venture to guess that this is all a huge XY problem.
Hi all, Many displays of time show for instance 11:58 meaning the hour is 11 am and 58 minutes past the hour. I am using the ds3231 real time clock. I am getting the hour and minute from it. How can I print it out like 11:58?
Can this be done without using incomprehensible symbols like '%'?
This topic seems to be a quite related to yours about printing time. Why did you opened a new thread rather than using a previous one?
In addition, you are again asking such basic questions that it would be better for you to find a solution yourself
What is the question anyway? If you have hours and minutes as two numbers, what's the problem with printing the hour first, then the colon, then the minutes?
You've been here for four years and don't know how to print two numbers?
Why did you start a new topic on the same subject ?
Your two or more topics on the same or similar subject have been merged.
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.