dusk2dawn issue

I am trying to use the dusk2dawn library, and have been unable to get it to function how I expect. It is supposed to return sunset and sunrise times of minutes from midnight. It is returning -169 for sunrise and 531 for sunset. This was the same if I used the time from the RTC or entered it manually. What am I doing wrong?

#include <Dusk2Dawn.h>
#include "RTClib.h"
RTC_DS3231 rtc;

void setup() {
 Serial.begin (9600);
 while (!Serial); // wait for serial port to connect. Needed for native USB
 
 if (rtc.lostPower()) 
 {
 Serial.println("RTC lost power, let's set the time!");
 rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
 }
}


void loop() {
 int hours;
 DateTime now = rtc.now();
 hours = now.hour() * 60 + now.minute(); // minutes since midnight

 Dusk2Dawn fburg(38.300713, 77.375166,-5);
 int rise = fburg.sunrise(now.year(), now.month(), now.day(), true);
 int set = fburg.sunset(now.year(), now.month(), now.day(), true);
 
 Serial.println(rise);
 Serial.println(set);
 delay(10000);
}

Please supply a link to the library. FYI, you don't really need a library for this, the AVR GCC native time.h has functions to obtain sunrise and sunset times.

Dusk2Dawn was suggested to me, but if there is a native way to accomplish the same thing, I'll look into it.

I looked at Dusk2Dawn a while back, and lost confidence when I saw this comment:

  // Advance the calculated time by a fraction of itself. I've no idea what the
  // purpose of this is.
  newJday    = jday + timeUTC / (60 * 24);
  newTimeUTC = sunriseSetUTC(isRise, newJday, _latitude, _longitude);

This clearly indicates that the author does not understand, and did not carefully test the code they cribbed from somewhere else.

In fact, it makes no difference if you add that fraction. And it shouldn't unless the time you enter is near midnight, pushing you, in theory, ahead one day. The times of sunrise and sunset depend only on the date.

A reliable and more useful solar position library for Arduino may be found here: