Hello.
I have been mostly focused at learning C but have now moved to look more at C++, but I get rather confused by my situation.
There are a collection of libraries that are used together:
Time
TimeAlarms
DS3232RTC
I am using an Arduino Due so I have to instantiate an object of DS3232RTC(as opposed to use the one instantiated within the library files such as when one uses a AVR based Arduino), the sketch contains these two things(but more functions from DS3232RTC might be used later):
#include <TimeLib.h>
#include <TimeAlarms.h>
#include <DS3232RTC.h>
DS3232RTC myRTC;
void setup()
{
setSyncProvider(myRTC.get); // identify the external time provider setSyncProvider(myRTC.get);
setSyncInterval(30); // set the number of seconds between re-sync
}
But now I am writing a class that will manage everything that got to do with the Time, TimeAlarms and RTC3232RTC libraries, both Time and TimeAlarms contains instantiations for those respective classes that I can use but I still need to instantiate:
DS3232RTC myRTC;
and use:
setSyncProvider(myRTC.get); // identify the external time provider setSyncProvider(myRTC.get);
But I don't understand how I should do that, I am reading about using objects within a class and instantiation inside of classes but it just makes me confused.
If I simply would write a class like this:
#include <TimeLib.h>
#include <TimeAlarms.h>
#include <DS3232RTC.h>
// Assume standard #ifndef claus.
class theClass
{
public:
theClass();
void begin()
{
setSyncProvider(myRTC.get);
}
DS3232RTC myRTC;
};
I didn't want to split this up into a .h code segment and a .cpp segment so it might look a little funny.
But would that be enough?
Would the object 'myRTC' be instantiated properly so that it can provide the 'myRTC.get' function or should I somehow use the 'theClass' constructor with a list to instantiate the DS3232RTC object?
There are so many things that might be wrong right now that I cannot be sure why the code don't work if it wouldn't work and it will still be some time before the code is written well enough that it actually could work.
Regards