DS3231 RTClib.h

I have my code correctly set up to adjust the time on a DS3231 with a button press.

Typical lines include:

rtc.adjust(rtc.now()+3600); //add one hour to time

and

rtc.adjust(rtc.now()+60); //add one minute to time

However, I am finding it difficult to set the seconds to 0.

Every time I button press for +60 I would like to set the seconds to 0. To overcome the issue of +60 when on 59 secconds and the time jumping 2 minutes (120 seconds).

What can I use in conjunction with rtc.adjust to set seconds to 0 on a button press? Is there a rounding function as part of the library? Or what other methods could I use?

Any help, guidance or direction would be greatly appreciated.

Try this:

    DateTime temp = rtc.now() + 60; //increment by 60 seconds so library handles rollover to next hour/day
    rtc.adjust( DateTime(temp.year(), temp.month(), temp.day(), temp.hour(), temp.minute(), 0) );

PERFECT! Just had an oppotunity to try this. Works great - was driving me crazy!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.