How do I read this code?

I'm trying to figure out how to read this code so I can reduce the battery reading time to 1 minute or even 2 minutes would work.

time_t addMinutes(time_t t, unsigned long minutes) {
__ return t + minutes*60;__
}
nextBatteryReadingTime = addMinutes(n,1);

Thanks again!

time_t addMinutes(time_t t, unsigned long minutes) {
    return t + minutes*60;
}

nextBatteryReadingTime = addMinutes(n,1);

It is defining a function called addMinutes() that returns a value of type time_t.

I have no idea what sort of value that is. It must be defined elsewhere in the code that you did not show us.

The function needs two parameters. It calls one of them t and it has also the type time_t. The other parameter is called minutes and its type is unsigned long.

It takes those parameter values, multiplies the minutes by 60 and adds it to the t value and it returns the result.

I suspect you will be able to figure out the last line yourself.

...R

time_t is a type representing time, usually the number of seconds which have passed since Jan 1 1970 00:00 UTC

time_t is typically defined in a header file <time.h> which includes some arithmetic functions, which return time_t values.

So, nextBatteryReadingTime is of type time_t
which leaves you to find out where n comes from.

It looks like 'nextBatteryReadingTime' is set to one minute after the time in 'n';

There is no way to know why the 'battery reading time' isn't already one minute without seeing the rest of the code.

Here's more of it.

time_t getCurrentTime() {
** // returns number of seconds since 1970**
** setClockPower(HIGH);**
** setSyncProvider(RTC.get); // the function to get the time from the RTC**
** time_t n = now();**
** return n;**

j_dub:
Here's more of it.

I assume you know how to figure it out now on the basis of the earlier replies and your other researches.

...R

I didn't write the code and I'm slowly trying to figure out what does what so I can understand what's going on and take over the project.

Well can you tell us what parts of the code in Reply #4 that you do understand and what parts you don't understand?

...R