Need help with RTClib

Hi guys!
I trying to make this project Светильник-будильник на Arduino
But using TinyRTC with DS1307.

#include <Wire.h>
#include <Time.h>
#include <LiquidCrystal_I2C.h>
#include <AlarmController.h>
#include <AlarmSettings.h>
#include <Bounce.h>
#include <Alarm.h>

const uint8_t snoozePin = 2;    //Purple
const uint8_t leftPin = 3;      //Green
const uint8_t rightPin = 4;     //Brown
const uint8_t upPin = 5;        //Blue
const uint8_t downPin = 6;      //Orange
const uint8_t okPin = 8;        //Yellow
const uint8_t cancelPin = 8;    //Grey
const uint8_t ledPin = 9;       //White

const uint8_t buzzerPin = 13;

const uint8_t bounceDelay = 8;

double fadeValue = 0.0;
unsigned long timeStart = 0;
unsigned long timeHigh = 0;
unsigned long timeOn = 0;
unsigned long timeOnPrev = 0;
unsigned long buzzerStart = 0;
//                      x        x        x        x        x      x        x      x        x      x      x        x      x      x        x      x      x      x        x      x      x      x        x      x      x      x      x        x      x      x      x      x
const int buzzerP[] = {150,2000,150,2000,150,2000,150,2000,150,80,150,2000,150,80,150,2000,150,80,150,80,150,2000,150,80,150,80,150,2000,150,80,150,80,150,80,150,2000,150,80,150,80,150,80,150,2000,150,80,150,80,150,80,150,80,150,2000,150,80,150,80,150,80,150,80,150,1000};
const int buzzerPL = 64;
const uint8_t buzzerL = 54;
int buzzerPI = 0;

 AlarmSettings set;
 LiquidCrystal_I2C lcd(0x27,16,2);

 AlarmController ac(&set,&lcd,ledPin);

 Bounce btnLeft = Bounce(leftPin,bounceDelay);
 Bounce btnRight = Bounce(rightPin,bounceDelay);
 Bounce btnUp = Bounce(upPin,bounceDelay);
 Bounce btnDown = Bounce(downPin,bounceDelay);
 Bounce btnOK = Bounce(okPin,bounceDelay);
 Bounce btnCancel = Bounce(cancelPin,bounceDelay);
 Bounce btnSnooze = Bounce(snoozePin,bounceDelay);

void setup()  {
   pinMode(ledPin, OUTPUT);
   pinMode(snoozePin, INPUT);
   pinMode(leftPin, INPUT);
   pinMode(rightPin, INPUT);
   pinMode(upPin, INPUT);
   pinMode(downPin, INPUT);
   pinMode(okPin, INPUT);
   pinMode(cancelPin, INPUT);
   pinMode(buzzerPin, OUTPUT);
   timeStart = millis();
   timeOn = millis();
   timeOnPrev = timeOn;
   lcd.init(); 
   lcd.setBacklight(1);
   lcd.home();
  
   lcd.print(F("setup   "));

   uint8_t ledOff[8] =     {0b00000,
                            0b00000,
                            0b00000,
                            0b00000,
                            0b00100,
                            0b01110,
                            0b01110,
                            0b01110 };
   uint8_t ledOn[8] = {0b00100,
                       0b10101,
                   0b10101,
                   0b00000,
                   0b00100,
                   0b01110,
                   0b01110,
                   0b01110 };

   uint8_t checkbox1[8] = {0b00000,
                           0b11111,
                       0b10001,
                       0b10001,
                       0b10001,
                       0b10001,
                       0b11111,
                       0b00000 };

   uint8_t checkbox2[8] = {0b00000,
                           0b11111,
                       0b10001,
                       0b10101,
                       0b10101,
                       0b10001,
                       0b11111,
                       0b00000 };

   lcd.createChar(0b00000, ledOff);
   lcd.createChar(0b00001, ledOn);
  
   lcd.createChar(0b00010, checkbox1);
   lcd.createChar(0b00011, checkbox2);

   digitalWrite(buzzerPin, LOW);
   analogWrite(ledPin, 0);

   ac.setMakeLight(analogWrite);
}

void loop()  {
   //update time
   timeOn = millis();
   if(timeOn<timeOnPrev) { //overflow!!
     set.getTime()->addMillis((4294967295ul - timeOnPrev) + timeOn);
   }
   else{
     set.getTime()->addMillis(timeOn - timeOnPrev);
   }
   timeOnPrev = timeOn;
  
   //update AlarmState
   ac.checkAlarmState();
  
   //make noise?
   if(ac.mustMakeNoise()) {
     if(buzzerPI % 2 == 0) {
       digitalWrite(buzzerPin, HIGH);
     }
     else {
       digitalWrite(buzzerPin, LOW);
     }
     if(abs(millis() - buzzerStart) > buzzerP[buzzerPI]) {
       buzzerPI++;
       if(buzzerPI == buzzerPL)
         buzzerPI = buzzerL;
       buzzerStart = millis();
     }
   }
   else {
     buzzerPI = 0;
     digitalWrite(buzzerPin, LOW);
   }
  
   //update LCD
   ac.printLCD();

   //check snooze-button
   btnSnooze.update();
   if(btnSnooze.risingEdge()) {
     ac.doSnooze();
     if(ac.getAlarmState() == 0) {
       timeStart = millis();
       btnSnooze.update();
       ac.printLCD();
       fadeValue = 0.0;
       analogWrite(ledPin,round(fadeValue));
       while(btnSnooze.read() == HIGH) {
         if(abs(millis() - timeStart) > 600) {
           //fadeValue += 15;
           fadeValue += (fadeValue / 600) + 1;
           if(fadeValue > 255) {
             fadeValue = 255.0;
           }
           analogWrite(ledPin,round(fadeValue));
           delay(10);
         }
         btnSnooze.update();
       }
     }
   }

   //Check other buttons
   btnLeft.update();
   btnRight.update();
   btnUp.update();
   btnDown.update();
   btnOK.update();
   btnCancel.update();

   if(btnOK.risingEdge()) {
     ac.doOK();
   }
   else if(btnCancel.risingEdge()) {
     ac.doCancel();
   }
   else if(btnLeft.risingEdge()) {
     ac.doLeft();
   }
   else if(btnLeft.fallingEdge()) {
     ac.endLeft();
   }
   else if(btnRight.risingEdge()) {
     ac.doRight();
   }
   else if(btnRight.fallingEdge()) {
     ac.endRight();
   }
   else if(btnUp.risingEdge()) {
     ac.doUp();
     btnUp.update();
     timeStart = millis();
     ac.printLCD();
     while(btnUp.read() == HIGH) {
       if(abs(millis() - timeStart) > 800) {
         ac.doUp();
         ac.printLCD();
         delay(140);
       }
       btnUp.update();
     }
   }
   else if(btnDown.risingEdge()) {
     ac.doDown();
     btnUp.update();
     timeStart = millis();
     ac.printLCD();
     while(btnDown.read() == HIGH) {
       if(abs(millis() - timeStart) > 800) {
         ac.doDown();
         ac.printLCD();
         delay(140);
       }
       btnDown.update();
     }
   }
  
}

In the original version starting time set at the string of library AlarmSettings:
In with part of AlarmSettings

/*************************
 ** AlarmSettings.cpp
 ************************/

#include "AlarmSettings.h"

char* _tomorrow = "Tomorrow";

 AlarmSettings::AlarmSettings() {
   _wakeUpDur = 30;
   _wakeUpLum = 255;
   _snoozeDur = 5;
   _backlightDur = 5;
   _fadeOutDur = 30;
   _fadeOutActive = false;
   _time = new Time(0,13,37,00);
   _dayAlarm = new Alarm();
   _weekAlarm = new WeekAlarm();
   _alarmCfgNo = 7;
}

_time = new Time(0,13,37,00);

I want to use real time got from DS1307 using RTClib, but I don't know to do it?
How I can get data from RTClib and put it to AlarmSettings?
So I really need your help.

AlarmSettings.cpp (7.64 KB)

AlarmSettings.h (1.9 KB)

RTClib.cpp (13.8 KB)

RTClib.h (4.33 KB)

I want to use real time got from DS1307 using RTClib, but I don't know to do it?

You want to use the time you read from the DS1307 that you haven't started to set the time? Really?

Yes ,I want to start with the time got from DS1307.
So I think I should use the data from RTClib at the string:
_time = new Time(0,13,37,00);
but how I should write it??

Yes ,I want to start with the time got from DS1307.

That's the part I don't understand. If you've already started the DS1307, there is no need to set the time again, unless you changed the battery.

If you haven't started the DS1307 yet, or you have replaced the battery, then the DS1307 has no idea what the date or time is, so reading garbage from it is pointless.

When this sketch starts,it starts with time setup manualy (13:37:00), but i need that at any time it starts, it starts with the time got from DS1307.

So, do you know how to get the time/date from the DS1307?

If so, then, you can simply replace the hardcoded values with values you get from the RTC.

Exactly how, I can't tell you, since I have no idea how the Time class is defined. A 4 argument constructor seems weird.

PaulS:
So, do you know how to get the time/date from the DS1307?

If so, then, you can simply replace the hardcoded values with values you get from the RTC.

Exactly how, I can't tell you, since I have no idea how the Time class is defined. A 4 argument constructor seems weird.

I know how to get the time from DS1307.
This is an example from RTClib.

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {

#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif

  Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
}

void loop () {
    DateTime now = rtc.now();
    
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    
    Serial.print(" since midnight 1/1/1970 = ");
    Serial.print(now.unixtime());
    Serial.print("s = ");
    Serial.print(now.unixtime() / 86400L);
    Serial.println("d");
    
    // calculate a date which is 7 days and 30 seconds into the future
    DateTime future (now + TimeSpan(7,12,30,6));
    
    Serial.print(" now + 7d + 30s: ");
    Serial.print(future.year(), DEC);
    Serial.print('/');
    Serial.print(future.month(), DEC);
    Serial.print('/');
    Serial.print(future.day(), DEC);
    Serial.print(' ');
    Serial.print(future.hour(), DEC);
    Serial.print(':');
    Serial.print(future.minute(), DEC);
    Serial.print(':');
    Serial.print(future.second(), DEC);
    Serial.println();
    
    Serial.println();
    delay(3000);
}

The main problem is to take data from one library RTClib and get it not to the sketch but to another library AlarmSettings.
I suppose something should be writing at the AlarmSettings.h file.

/************************
 ** AlarmSettings.h
 ************************/

#ifndef ALARMSETTINGS_H
#define ALARMSETTINGS_H

#include <Time.h>
#include "Alarm.h"
#include "WeekAlarm.h"
#include "LiquidCrystal_I2C.h"
#include <RTClib.h>

class AlarmSettings {
  public:
    
    AlarmSettings();



    void setWakeUpDur(uint8_t);
    uint8_t getWakeUpDur();
    void setWakeUpLum(uint8_t);
    uint8_t getWakeUpLum();
    Time* getTime();
  

    void setTime(Time* time);
    Alarm* getDayAlarm();
    WeekAlarm* getWeekAlarm();
    uint8_t getAlarmConfigNumber();
    void setAlarmConfigNumber(uint8_t);
    char* getAlarmTitle();
    char* getAlarmTitle(uint8_t);
    uint8_t getAlarmHour();
    uint8_t getAlarmHour(uint8_t);
    void setAlarmHour(uint8_t);
    void setAlarmHour(uint8_t no,uint8_t hour);
    uint8_t getAlarmMin();
    uint8_t getAlarmMin(uint8_t no);
    void setAlarmMin(uint8_t);
    void setAlarmMin(uint8_t no,uint8_t hour);
    bool isAlarmActive();
    bool isAlarmActive(uint8_t);
    void setAlarmActive(bool);
    void setAlarmActive(uint8_t,bool);
    uint8_t getFirstActiveAlarmNo();
    uint8_t getSecondActiveAlarmNo();
    uint8_t getAlarmCount();
    uint8_t getSnoozeDur();
    void setSnoozeDur(uint8_t);
    uint8_t getBacklightDur();
    void setBacklightDur(uint8_t);
    void setFadeOutDur(uint8_t);
    void setFadeOutActive(bool);
    uint8_t getFadeOutDur();
    bool isFadeOutActive();
      uint8_t _getDay;
      uint8_t _getHour;
      uint8_t _getMin;
      uint8_t _getSec;


  private:
    uint8_t _wakeUpDur;
    uint8_t _wakeUpLum;
    uint8_t _snoozeDur;
    uint8_t _backlightDur;
    uint8_t _fadeOutDur;
    bool _fadeOutActive;
    Time* _time;
    Alarm* _dayAlarm;
    WeekAlarm* _weekAlarm;


    uint8_t _alarmCfgNo;  //0 for monday, 1 for tuesday, ... , 6 for sunday, 7 for tomorrow
};


#endif

And how i can say to AlarmSettings.cpp to take data from RTClib.h and move it to the variables:
uint8_t _getDay;
uint8_t _getHour;
uint8_t _getMin;
uint8_t _getSec;
???

And how i can say to AlarmSettings.cpp to take data from RTClib.h and move it to the variables:

You can't. The AlarmSettings library can't be told to do anything. YOU can assign values to the variables that are defined FOR AN INSTANCE OF THE AlarmSettings class.

byte h = getValueForHourFromRTCLib();

AlarmSettings tooDamnedEarly;
tooDamnedEarly._getHour = h;

The name _getHour is stupid for a variable that can be set. It is stupid to have public members like that. Time should be adjusted using SetXxxx() methods.