Passing E-number value instead of name

Using arduino r4

Trying to set the RTC

Every param except the month can be passed as an integer - accept the month which is passed as an enum

Eg rtctime(dd,Month::august,yyyy……

I have the month as an integer value 0-11 and would like to pass this instead.

I am more a C# programmer and don’t do much with enums.

Can anyone advise a working syntax.

Stan

Please post a sketch that illustrates your problem, using code tags when you do

1 Like

The month enum number will likely resolve to an int in the range 0-11 anyway. Just try using it. You may find that you have an off by one error to fix or perhaps you'll be lucky. Cast it if you have to.

1 Like

Which RTC? Which Board? Which RTC Library?

2 Likes

Arduino uno r4
Onboard rtc

Small sketch below;

As mentioned above this is for an arduino UNO R4

The 'try a cast suggestion was the clincher - this compiles - however I will have to wait until I get home (where the H/W is) to do a full test.

Will advise.

Stan

// Include the RTC library
#include "RTC.h"


/* -------------------------------------------------------------------------- */
void setup() {
  /* -------------------------------------------------------------------------- */
  //Initialize serial and wait for port to open:

 
int dd=21;
int mm=3;
int yyyy=2023;
int hh=17;
int MM=12;
int ss=04;

//  21-March-2023 17:12:04
 RTC.begin();
 RTCTime timeToSet(dd, Month::JUNE, yyyy, hh, MM, ss, DayOfWeek::WEDNESDAY, SaveLight::SAVING_TIME_ACTIVE);   // This works (Compiles)
RTC.setTime(timeToSet);

RTCTime timeToSet2(dd, (Month)mm-1, yyyy, hh, MM, ss, DayOfWeek::WEDNESDAY, SaveLight::SAVING_TIME_ACTIVE); // This compiles 
RTC.setTime(timeToSet2);
}



/* -------------------------------------------------------------------------- */
void loop() {

 
}

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