RTC stops when button is pushed

Hi, i’m having a small problem with my project.

I’m making a clock with an RTC (DS1307) the clock runs perfectly but when I push a button to make the minutes go up by 1 the time stops briefly. It stops when i push the button but goes on when the code behind the button is executed. So if i press the button multiple times repeatedly, the time stops for a while (as long as i’m pressing and releasing the button, the time doesn’t run). I have tried several ways of coding the button but every ‘solution’ has the same result: the time stops briefly and then starts again after the code of the button is done.

I was hoping you guys would have an alternative solution :slight_smile:

Here is my code:

#include <Time.h>
#include <DS1307RTC.h>
#include <Wire.h>

const int minuteButton = 2;

void setup(void) 
{
  Serial.begin(9600);
  pinMode(minuteButton, INPUT);
  digitalWrite(minuteButton, HIGH);
  setSyncProvider(RTC.get);             
  setSyncInterval(60);            
  
  setTime(12, 34, 56, 1, 1, 2013);   //12:34:56 just a default time to test
  RTC.set(now());
}

void loop(void)
{
  buttons();
}

these are the different things i tried for the button (without succes):
1

void buttons()
{
  if(digitalRead(minuteButton) == HIGH && digitalRead(alarmButton) == LOW && test == 0)
  {
      adjustTime(60);
      RTC.set(now());
      test += 1;
  }
  else if(digitalRead(minuteButton) == HIGH && digitalRead(alarmButton) == HIGH && test == 0)
  {
      tmrMin += 1;
      setTmr();
      checkTmrOverflowUp();
      test += 1;
  }
}

2

void buttons()
{
  if(digitalRead(minuteButton) == HIGH)
  {
    delay(50);
    
    if(digitalRead(minuteButton) == LOW)
    {
      adjustTime(60);
      RTC.set(now());
    }
  }
}

3

boolean buttonPressed()
{
static boolean buttonState;             // the current reading from the input pin
static boolean lastButtonState = LOW;   // the previous reading from the input pin
static boolean result = false;       // the value returned by function
static long lastDebounceTime = 0;  // the last time the output pin was toggled
const long debounceDelay = 50;    // the debounce time; increase if the output flickers

  // read the state of the switch into a local variable:
  int reading = digitalRead(buttonPin);
  // If the switch changed, due to noise or pressing:
  if (reading != lastButtonState) { 
    lastDebounceTime = millis();    // reset the debouncing timer
  }   
  if ((millis() - lastDebounceTime) > debounceDelay) {    
    if( buttonState != reading){ // if the state has changed
       if(reading == LOW)  // change this to HIGH if using pull-down resistors
          result = true;   
        buttonState = reading; // stable so in state long enough
    }    
  }
  lastButtonState = reading;
  if( result == true){
      result = false; // only return true once per press
      return true;  
  }
  return false;
}

Thanks in advance!

What does adjustTime() do?

adjustTime(x); adds x seconds to the time (a minute), it's a function from the Time-library