Set the time with RtcDS1302 library

Hi - I'm using the library at:
to display the time. The example code shows setting of the time from the current time. I need to set the time according to a user input (for a Nixie Clock project), so I'm looking at the function in the library code:

 void SetDateTime(const RtcDateTime& dt)
        // set the date time

        _wire.write(Uint8ToBcd(dt.Hour())); // 24 hour mode only

        // RTC Hardware Day of Week is 1-7, 1 = Monday
        // convert our Day of Week to Rtc Day of Week
        uint8_t rtcDow = RtcDateTime::ConvertDowToRtc(dt.DayOfWeek());

        _wire.write(Uint8ToBcd(dt.Year() - 2000));
        _wire.write(0); // no write protect, as all of this is ignored if it is protected


I'm battling to work out how I can use this function to set the individual hours and minutes:
Something like:

mymin = 10; // for example
myhour = 2; // for example
Rtc.SetDateTime(myhour, mymin)

I'm sure it's simple, but I'm not quite getting what to do at the top level of the code in my sketch.
Thanks and regards

That function takes a reference to a RtcDateTime object as its argument. You can find the definition of this class in RtcDateTime.h.

Thanks - but I suppose I don't really know what I'm doing: I tried this:

void setDs1302()
  char datestring[20];
  char setmonth = 9;
  char setday = 4;
  int setyear = 2021;
  char sethour = 8;
  char setmin = 23;
  char setsec = 0; 
             PSTR("%04u/%02u/%02u %02u:%02u:%02u"),
             setsec );


In order to hard code a time/date for testing: but I just get this output:

2021/09/04 08:23:00
01/01/2000 00:37:34
01/01/2000 00:37:36
01/01/2000 00:37:38
01/01/2000 00:37:40
01/01/2000 00:37:42
01/01/2000 00:37:44
01/01/2000 00:37:46

I think I missed the ':' required the object format:
this post helped:

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