Skip to main content
1 of 2
Michel Keijzers
  • 13k
  • 7
  • 42
  • 59

You don't need to use the static keyword.

The cleanest solution is to define DateTime outside of the loop function:

DateTime now;

This will allocate the memory, and call the constructor of the class DateTime initializing it.

In case you would need a basic variable (like an int), you should initialize it, like:

int now = 0;

When you use it in setup or loop you use the created instance (without the class name to declare it):

void loop() {
   ...
   now = rtc.now();
}

Also, find a better name for now, because the variable is the same as the rtc's function now.

Michel Keijzers
  • 13k
  • 7
  • 42
  • 59