I am trying to get from the ds3231 only the month or the day of the month instead of everything; date and time. That works ok.
In the library referred to the author uses RTC setters and getters. I have copied these onto a sketch. I have set the month as '6' which should be June. Then I expected from the sketch to get a print out of '6'.
It turns out there are many errors in the compiling. I have included the sketch. Could anyone point out where the errors are?
#include <DS323x.h>
DS323x rtc;
void setup()
{
Serial.begin(115200);
Wire.begin();
delay(2000);
rtc.attach(Wire);
bool month(const uint8_t 6 );//this is a rtc setter
}
void loop()
{
Serial.println(uint8_t month());//this is a rtc getter
delay(1000);
}
The function for the setter is bool month(const uint8_t m); you use it like month(6). You can check the return value to make sure that the function succeeded.
The function for the getter is uint8_t month(); your use it like month().
Both functions (methods) are part of the DS323x class so you need to access them through an instance of the class; that instance is rtc.
#include <DS323x.h>
DS323x rtc;
void setup()
{
Serial.begin(115200);
Wire.begin();
delay(2000);
rtc.attach(Wire);
rtc.month(6);//this is a rtc setter
}
void loop()
{
Serial.println(rtc.month());//this is a rtc getter
delay(1000);
}
If you want to see if the setter succeeded, you can use
bool result = rtc.month(6);//this is a rtc setter
Serial.println(result);
Codes not tested but they do compile.
PS
In future, please provide a link to the library or how you installed it so we don't have to hunt for it.
Library used: GitHub - hideakitai/DS323x: Arduino library for DS3231/DS3232 Extremely Accurate I²C-Integrated RTC/TCXO/Crystal
And another PS:
In future include the errors as well (using code tags). This one was easy to spot, others might not be.
compiled and worked. returned 6 on serial monitor. just one more thing. what would be the code if I want the day of the month? I have taken on board what you say about the source and showing error codes. there was so many error codes I didn't know where to start. I never liked using that bool reference in the first place.
now I can load the RTC with the date and time and get back just the month and hopefully the day or any other part of it. 'year, month, day of month, hour, minute'.
Have a look at the available getters and decide which one makes sense.
No idea why. It had nothing to do with your original setter problem.
I suggest that you learn a bit more about C (or C++).