hello. I need some help. I get different unix time depending on where in the code i put the rtc.now(); function. Please help
#include "RTClib.h"
#include <SevSeg.h>
// Init the DS3231 using the hardware interface
RTC_DS1307 rtc;
unsigned long currentunix;
unsigned long togetherunix = 1566727200;
unsigned long sinceunix;
unsigned long sincedays;
SevSeg sevseg; //Instantiate a seven segment controller object
void setup()
{
Serial.begin(57600);
bool resistorsOnSegments = true;
bool updateWithDelaysIn = true;
byte hardwareConfig = COMMON_CATHODE;
byte numDigits = 4;
byte digitPins[] = {10, 11, 12, 13}; //Digits: 1,2,3,4 <--put one resistor (ex: 220 Ohms, or 330 Ohms, etc, on each digit pin)
byte segmentPins[] = {9, 2, 3, 5, 6, 8, 7, 4}; //Segments: A,B,C,D,E,F,G,Period
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins);
sevseg.setBrightness(10); //Note: 100 brightness simply corresponds to a delay of 2000us after lighting each segment. A brightness of 0
//is a delay of 1us; it doesn't really affect brightness as much as it affects update rate (frequency).
//Therefore, for a 4-digit 7-segment + pd, COMMON_ANODE display, the max update rate for a "brightness" of 100 is 1/(2000us8) = 62.5Hz.
//I am choosing a "brightness" of 10 because it increases the max update rate to approx. 1/(200us8) = 625Hz.
//This is preferable, as it decreases aliasing when recording the display with a video camera....I think.
}
void loop()
{
DateTime now = rtc.now();
currentunix = now.unixtime();
sinceunix = currentunix - togetherunix;
sincedays = sinceunix / 60;
sincedays = sincedays / 60;
sincedays = sincedays / 24;
sevseg.setNumber(sincedays, 0);
sevseg.refreshDisplay(); // Must run repeatedly; don't use blocking code (ex: delay()) in the loop() function or this won't work right
}