RTC Changing time with external buttons

Hello forum!

Im trying to be able to change time on my RTC DS3231 with external buttons. I just want to be able to change hour and minutes.

So i found this code and got it up and running, all seems to work just fine.

#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t
 
void setup()  {
  Serial.begin(9600); // start the serial connection to the PC.
 
  pinMode(2, INPUT);       // set pin 2 as an input
  digitalWrite(2, HIGH);   // activate internal pullup resistor on pin 2
  pinMode(3, INPUT);       // set pin 3 as an input
  digitalWrite(3, HIGH);   // activate internal pullup resistor on pin 3
  pinMode(4, INPUT);       // set pin 4 as an input
  digitalWrite(4, HIGH);   // activate internal pullup resistor on pin 4
 
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  setSyncInterval(60);        // set the number of seconds between re-sync
 
  if(timeStatus()!= timeSet)
     Serial.println("Unable to sync with the RTC.");
  else
     Serial.println("RTC has been read.");
}
 
void loop()
{
  if (digitalRead(2) == LOW) {         // Zero the minutes!
                                       // setting the onboard time to 0 minutes.
    setTime(hour(),0,second(),day(),month(), year());
    RTC.set(now());                    // sending the onboard time to the RTC.
    Serial.println("Minutes Reset.");  // send confirmation to the PC.
 
  }
 
  // *** had to adjust the adjustTime function in the Time library.
  // Inside Time.cpp, the adjustTime method was replaced with:
  //
  //  void adjustTime(long adjustment){
  //    setTime(sysTime + adjustment);
  //  }
  //
 
  if (digitalRead(3) == LOW) {         // add an hour!
    adjustTime(3600);                  // adjust onboard time by +3600 seconds (1hr) ***
    RTC.set(now());                    // sending the onboard time to the RTC.
    Serial.println("Added an hour.");  // send confirmation to the PC.
  }
 
  if (digitalRead(4) == LOW) {         // add a minute!
    adjustTime(60);                    // adjust onboard time by +60 seconds (1min) ***
    RTC.set(now());                    // sending the onboard time to the RTC.
    Serial.println("Added a minute."); // send confirmation to the PC.
  }
 
  // this section is for setting the rtc chip from the serial terminal.
  if(Serial.available()){
     time_t t = processSyncMessage();
     if(t >0)
     {
        RTC.set(t);   // set the RTC and the system time to the received value
        setTime(t);
     }
  }
 
  digitalClockDisplay();  // sends an update of the time to the PC.
  delay(1000);            // wait for a bit.
}
 
void digitalClockDisplay(){
  // digital clock display of the time over serial
  Serial.print(hour());
  Serial.print(":");
  printDigits(minute());
  Serial.print(":");
  printDigits(second());
  Serial.println();
 
}
 
void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}
 
/*  code to process time sync messages from the serial port   */
#define TIME_MSG_LEN  11   // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER  'T'   // Header tag for serial time sync message
 
time_t processSyncMessage() {
  // return the time if a valid sync message is received on the serial port.
  while(Serial.available() >=  TIME_MSG_LEN ){  // time message consists of a header and ten ascii digits
    char c = Serial.read() ;
    Serial.print(c);
    if( c == TIME_HEADER ) {
      time_t pctime = 0;
      for(int i=0; i < TIME_MSG_LEN -1; i++){
        c = Serial.read();
        if( c >= '0' && c <= '9'){
          pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
        }
      }
      return pctime;
    }
  }
  return 0;
}

Problem is that when i try to incorporate this to my main code im getting error compilings.

I'll post my main code beneath this post, i suspect it has sometihng to do with <Time.h> and <DS1307RTC.h>
not working well together with the ones i've already put in my code which is <RTClib.h>

I'm afraid that i will have to change my main code to fit with <Time.h> and <DS1307RTC.h>
and that would be quite difficult, atleast for my knowlege level..

So to my question; is there a way to do this without the use of Time.h?

Any tips or hints would be much obliged

My main code, i had to cut some of it in order to not reach the limit

#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;

// Display output pin assignments
#define MTEN Display1=Display1 | (1<<0)  
#define HALF Display1=Display1 | (1<<1)
#define QUARTER Display1=Display1 | (1<<2)
#define TWENTY Display1=Display1 | (1<<3)
#define MFIVE Display1=Display1 | (1<<4)
#define MINUTES Display1=Display1 | (1<<5)
#define PAST Display1=Display1 | (1<<6)
#define UNUSED1 Display1=Display1 | (1<<7)
#define TO Display2=Display2 | (1<<0)
#define ONE Display2=Display2 | (1<<1)
#define TWO Display2=Display2 | (1<<2)
#define THREE Display2=Display2 | (1<<3)
#define FOUR Display2=Display2 | (1<<4)
#define HFIVE Display2=Display2 | (1<<5)
#define SIX Display2=Display2 | (1<<6)
#define UNUSED2 Display2=Display2 | (1<<7)
#define SEVEN Display3=Display3 | (1<<0)

#define EIGHT Display3=Display3 | (1<<1)
#define NINE Display3=Display3 | (1<<2)
#define HTEN Display3=Display3 | (1<<3)
#define ELEVEN Display3=Display3 | (1<<4)
#define TWELVE Display3=Display3 | (1<<5)
#define OCLOCK  Display3=Display3 | (1<<6)
#define UNUSED3 Display3=Display3 | (1<<7)


static unsigned long msTick =0;  // the number of Millisecond Ticks since we last 
// incremented the second counter
int  count;
char Display1=0, Display2=0, Display3=0;
// hardware constants
int LEDClockPin=6;
int LEDDataPin=7;
int LEDStrobePin=8;
int MinuteButtonPin=2;
int HourButtonPin=3;
int PWMPin = 9;
int lightPin = 0;  //define a pin for Photo resistor


void setup()
{
  // initialise the hardware 
  // initialize the appropriate pins as outputs:
  pinMode(LEDClockPin, OUTPUT); 
  pinMode(LEDDataPin, OUTPUT); 
  pinMode(LEDStrobePin, OUTPUT); 
  //pinMode(BrightnessPin, INPUT);
  pinMode(MinuteButtonPin, INPUT); 
  pinMode(HourButtonPin, INPUT);
  pinMode(PWMPin, OUTPUT); 
  Serial.begin(19200);
  msTick=millis();      // Initialise the msTick counter

  Wire.begin();
  RTC.begin();

  //RTC.adjust(DateTime(__DATE__, __TIME__));
  if (! RTC.isrunning())
    Serial.println("RTC is NOT running!");

  displaytime();        // display the current time

}





void ledsoff(void) {

  Display1=0;

  Display2=0;

  Display3=0;

}





void WriteLEDs(void) {

  // Now we write the actual values to the hardware

  shiftOut(LEDDataPin, LEDClockPin, MSBFIRST, Display3);

  shiftOut(LEDDataPin, LEDClockPin, MSBFIRST, Display2);

  shiftOut(LEDDataPin, LEDClockPin, MSBFIRST, Display1);

  digitalWrite(LEDStrobePin,HIGH);

  delay(2);

  digitalWrite(LEDStrobePin,LOW); 

}





void displaytime(void)
{
  byte  hour,minute, second;
  DateTime now = RTC.now();
  hour=now.hour();
  minute=now.minute();
  second=now.second();



  // start by clearing the display to a known state

  ledsoff();