Using time.h and it's example.

I’ve got a 20x4 LCD, a DS3231 RTC, and a AM2302(Not Implemented yet)

I got them all working together using the Time.h library from the playground, but that library doesn’t like UTC time, while time.h from AVR libc needs UTC to calculate sunrise/sunset/moon position etc. I couldn’t figure out how to get the DS3231 library working with time.h vs Time.h without having both in the library which I don’t want to do, so I made my own way to get the time from my RTC (which is set in UTC) so I could give time.h the current time without needing Time.h.

I plan on implementing the output on the LCD in a MM-DD-YY HH:MM:SS AM/PM format and only updating the seconds as needed, updating the Temperature output from the AM2302 on the minute hand, and updating everything else on the hour hand using nested if statements (If Seconds wasn’t updated Minutes doesn’t need to etc) I’ve done this function using the Time.h library already so that isn’t going to be a problem.

The problem I’m having is figuring out a way to parse the example to get it into a readable format to me, the example for computing stuff is in (void SolarStuff()) at the bottom of the first code block, the 2nd code block is the example I’m working from.

eot = equation_of_time(&now) / 60.0;

Gives me eot to work with, I understand that,

But what is happening here?

d = daylight_seconds(&now);
gmtime_r(&d,&daylen);

d = solar_noon(&now);
localtime_r(&d,&noon);

#include <time.h>
#include <util/usa_dst.h>
#include <util/eu_dst.h>
#include <Wire.h>


#define MY_LATITUDE 27L * ONE_HOUR
#define MY_LONGITUDE -82L * ONE_HOUR
#define MY_TIME_ZONE -5 * ONE_HOUR
#define MY_DST usa_dst
// #define MY_DST eu_dst
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
//byte Time[8];
byte RTCReturn[7];

void setup() {
  Serial.begin(9600);
  settime();


;
  
  // put your setup code here, to run once:

}

void loop(){

  /*
  time_t now, d;
  struct tm gm, lt, sid, daylen, noon, rise, set;
  char buff[26];
  double n, decl, eot;
  int i, phase;
  unsigned long m;
  char c;
  */
  //byte RTCReturn[8];
 // RTCTIMENOW();
  byte count = 0;
  while (count != 7){
    Serial.print(RTCReturn[count]);
    Serial.print("  /  ");
    count += 1;  
  }

  Serial.println();
  
  time_t now, d;
  struct tm gm, lt, sid, daylen, noon, rise, set;
  char buff[26];
  double n, decl, eot;
  int i, phase;
  unsigned long m;
  char c;

  time(&now);

  
  gmtime_r(&now,&gm);
  
  localtime_r(&now,&lt);

  eot = equation_of_time(&now) / 60.0;
  Serial.println(eot);
  phase = moon_phase(&now);
  Serial.println(phase);
  d = lm_sidereal(&now);
  gmtime_r(&d,&sid);
  
  
  decl = solar_declination(&now) * 57.3;
  
  d = daylight_seconds(&now);
  gmtime_r(&d,&daylen);
   
  d = solar_noon(&now);
  localtime_r(&d,&noon);

  d = sun_set(&now);
  localtime_r(&d,&set);

  d = sun_rise(&now);
  localtime_r(&d,&rise);
 // Serial.println(buff);

  delay(10000);


  
}

//byte RTCReturn[8];
int RTCTIMENOW() {
  Wire.beginTransmission(0x68); //DS3231 Address
  Wire.write(0); //Get to Start Address is RTC
  Wire.endTransmission();     // stop transmitting
  delay(100); //Give it time (Uknown if needed)
  lcd.setCursor(0, 0); //Setup LCD Position
  Wire.begin(); //Starting Wire up again?
  Wire.beginTransmission(0x68); //DS3231 Address
  
  byte SQUIL = Wire.requestFrom(0x68, 19); //Request 19 bytes from RTC Should be everything
  byte QUIL = Wire.endTransmission();  // Stop talking to RTC
  byte RTCArray[19]; //Initialize Byte container
  int counter = 0; //Initialize counter for filling Byte Container

  
  //Reads every byte available in WireBuffer putting it into the 19 byte storage RTCArray
  //The commented out things are to debug what the bytes say
  while (Wire.available()){
    //Serial.print(counter);
    //Serial.print("  ");
    RTCArray[counter] = Wire.read();
    ///printBits(RTCArray[counter]);
    //Serial.println();
    counter += 1;
      }

//Byte 0 from RTC is a BCD for Seconds, this section takes the byte, splits it, and returns Seconds as the Byte Seconds                       } 
    byte x = RTCArray[0];
    //byte x = 0xA7;  // For example...
    byte nibble1 = (byte) (x & 0x0F);
    byte nibble2 = (byte)((x & 0xF0) >> 4);
    byte Seconds = (int(nibble2)*10)+int(nibble1);

//Byte 1 from RTC is Minutes as BCD, this turns it into a byte
    x = RTCArray[1];
    //printBits(x);
    //Serial.println();
    nibble1 = (byte) (x & 0x0F);
    nibble2 = (byte)((x & 0xF0) >> 4);
    byte Minutes = (int(nibble2)*10)+int(nibble1);

// Byte 2 is BCD Hours, but includes a function for things to be in 24 or 12 horus with AM or PM, this function assumes a 24 hour clock
    x = RTCArray[2];
    //printBits(x);
    //Serial.println();
    nibble1 = (byte) (x & 0x0F);
    nibble2 = (byte)((x & 0xF0) >> 4);
    //printBits(nibble1);
    int Hours9 = int(nibble1);
    int  Hours10 = bitRead(nibble2,0);
    byte Hours = (Hours10*10) + Hours9;
    
//Byte 3 is Day of week and is the only information in the Day of Week 
    byte DayOfWeek = RTCArray[3];

//Byte 4 is the day month and is a BCD as well.
    x = RTCArray[4];
    nibble1 = (byte) (x & 0x0F);
    nibble2 = (byte)((x & 0xF0) >> 4);
    byte DayofMonth = (nibble2*10) + nibble1;
    
//Byte5 is the Month, the MSB is the Century and is ignored, this code will break in 2100
    byte Month = RTCArray[5];

//Byte6 is the year in BCD  
    x = RTCArray[6];
    //printBits(x);
    //Serial.println();
    nibble1 = (byte) (x & 0x0F);
    nibble2 = (byte)((x & 0xF0) >> 4);
    byte Year = (nibble2 * 10) + nibble1;

/* Byte 7 - 13 is Alarm Functions
 *  Byte 14 is Control bytes
 *  Byte 15 is Control and Status
 *  Byte 16 is Againg offset
 *  Byte 17 MSB of Temperature
 *  Byte 18 is LSB of Temperature
 */
 RTCReturn[0] = Year;
  RTCReturn[1] = Month;
   RTCReturn[2] = DayofMonth;
    RTCReturn[3] = DayOfWeek;
     RTCReturn[4] = Hours;
      RTCReturn[5] = Minutes;
       RTCReturn[6] = Seconds;
 return true;
  }




void printBits(byte myByte){
 for(byte mask = 0x80; mask; mask >>= 1){
   if(mask  & myByte)
       Serial.print('1');
   else
       Serial.print('0');
 }
}

void settime(){
    RTCTIMENOW();
  time_t systime;
  struct tm tmptr;
  int a[6];
  tmptr.tm_year = RTCReturn[0] + 100;
  tmptr.tm_mon = RTCReturn[1]-1;
  tmptr.tm_mday = RTCReturn[2];
  tmptr.tm_hour = RTCReturn[4];
  tmptr.tm_min = RTCReturn[5];
  tmptr.tm_sec = RTCReturn[6];
  tmptr.tm_isdst = -1;

  systime = mktime(&tmptr);
  set_system_time(systime);
  
}

void SolarStuff(){
  time_t now, d;
  struct tm gm, lt, sid, daylen, noon, rise, set;
  char buff[26];
  double n, decl, eot;
  int i, phase;
  //unsigned long m;
  char c;

  time(&now);

  
  gmtime_r(&now,&gm);
  
  localtime_r(&now,&lt);

  eot = equation_of_time(&now) / 60.0;

  phase = moon_phase(&now);
  
  d = lm_sidereal(&now);
  gmtime_r(&d,&sid);
  
  decl = solar_declination(&now) * 57.3;
  
  d = daylight_seconds(&now);
  gmtime_r(&d,&daylen);
   
  d = solar_noon(&now);
  localtime_r(&d,&noon);

  d = sun_set(&now);
  localtime_r(&d,&set);

  d = sun_rise(&now);
  localtime_r(&d,&rise);

}

Using this Example and using this library

http://paste.ubuntu.com/14677677/

and using this library