Digital clock problems

Hello, I am fairly new to arduino and started getting a bit more advanced so I had decided to make a digital clock that was able to be manually set using pushbuttons. One issue I ran into was that the buttons were not working as intended and that there was a type of delay to update the time when you push the button or it would not update at all. I was wondering if anyone would be able to help me figure out the problem with my code and or wiring?

#include <LiquidCrystal.h>

int seconds = 0;
int minutes = 0;
int hours = 0;


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  Serial.begin(9600);
  lcd.begin(16, 2); // Set up the number of columns and rows on the LCD.
  pinMode(A0, INPUT_PULLUP);
  pinMode(A1, INPUT_PULLUP);
  // Print a message to the LCD.
  lcd.print("Time in: Miami");
  
}

void loop()
{
  lcd.setCursor(0, 1);

  
  lcd.print(hours);
  lcd.print(":");
  lcd.print(minutes);
  lcd.print(":");
  lcd.print(seconds);
  lcd.print("__________");
  
 if(seconds < 60){
  delay(1000);
  seconds = seconds + 1;
  }else{
  	seconds = 0;
  }
  
  if(seconds > 59){
  minutes = minutes + 1;
  }else{
  	minutes = minutes;
  }
  
  if(minutes < 60){
  minutes = minutes;
  	hours = hours;
  }else{
  minutes = 0;
    hours = hours + 1;
  }
  
  if(hours < 24){
  hours = hours;
  }else{
    hours = 0;
    minutes = 0;
    seconds = 0;
  }
  
   if(digitalRead(A0) == LOW){
  minutes = minutes + 1;
    seconds = 0;
  }
  
  if(digitalRead(A1) == LOW){
  hours = hours + 1;
    
  }  

}//loop1

A delay of about a second, would you say?

Yes

I put the delay that you said to update the seconds variable every second, but I do not know if it impacts the pushbuttons updating the variables.

If you look at the blink without delay example in the IDE's examples, it will give hints on how to eliminate delays.

I will check that out, thank you!

It does.
It's the digital equivalent of twiddling your thumbs, sticking your fingers in your ears and going "la-la-la-la"

Yes, that is right and proper.

I presume your code is all all your own. It is probably kosher but definitely crude. There has to be better examples around. Yours is active for only a tiny fraction of the time and if you hold the button for less than one second, it probably won't work at all but, if you hold it down for 1.1 sec, I imagine you could get two advances.

Thank you for the solutions, which did end up working in the simulator, but when I used the same board, and pinout in the real thing, the pushbutton connected to A0 and A1 keeps printing out 14, and I have changed wires, and pushbuttons, but it still keeps not changing. Has anyone else ran into this problem or know how to fix it?

Never mind, I figured it out.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.