-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Hi,
I am trying to use the code for a Moon Clock I am making and while the Moonphases algorithm
works well I am having a strange problem. When I manually assign values to (year, month, day) the
moonPhases returns proper values but when I get the values from the RTC clock for exactly the same
date, moonPhases returns wrong results. (but when you print the read [year, month, day] the values
are correct).
Why is that?
Does it have to do with the DateTime class? https://adafruit.github.io/RTClib/html/class_date_time.html
p.s. The discrepancy first shows up in the following line of code of the MoonPhases( ) function.
unsigned long meeDT = pow((jd - 2382148), 2) / (41048480 * 86400);
#include <Wire.h>
#include "RTClib.h"
RTC_DS3231 rtc;
int nowDay = 31;
int nowMonth = 12;
int nowYear = 2020;
int moonPhase;
void setup() {
Serial.begin(57600);
}
void loop() {
DateTime now = rtc.now();
// If I read the values from the RTC, the moonPhases returns wrong results!
nowYear = now.year(); // result is 2020
nowMonth = now.month(); // result is 12
nowDay = now.day(); // result is 31
Serial.print( nowYear ); Serial.print( " " );
Serial.print( nowMonth ); Serial.print( " " );
Serial.print( nowDay ); Serial.print( " " );
moonPhase = moonPhases( nowYear, nowMonth, nowDay );
Serial.println( moonPhase );
}