Stopwatch arduin LCD 16x2

I made a Stopwatch with 2 buttons, I want that a button run the timer and pause if I press it again, and the other to reset the chronometer. I did the stopwach run but i can't make it pause, rerun and reset, can you guys help me?
there is the circuit and the code

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,4,5,6,7);
int botao1 = 8;
int botao2 = 9;
int estadoBotao1 = 0;
int estadoBotao2 = 0;
int sec, min, hora;
unsigned long zero;

void cronometro();
void pausa();

void setup(){
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Cronometro do");
delay(200);
lcd.setCursor(1,1);
lcd.print("Ian Rapini ._.");
delay(800);
lcd.clear();

pinMode(botao1, INPUT);
pinMode(botao2, INPUT);
sec = 0;
min = 0;
hora = 0;
zero = 0;
delay(300);
}

void loop(){

cronometro();

}

void cronometro(){
estadoBotao2 = digitalRead(botao2);
estadoBotao1 = digitalRead(botao1);

lcd.clear();
lcd.print("Clique no Botao");
delay(100);

if(estadoBotao2 == HIGH){
sec = 0;
min = 0;
hora = 0;
zero = 0;
lcd.clear();

while(estadoBotao1 == LOW){

 lcd.clear();
 lcd.home();

 if(millis() - zero > 1)

{
sec++;
zero = millis();
}

if(sec > 59)
{
lcd.setCursor(10, 1);
lcd.print(" ");
sec = 0;
min++;
}

if(min > 59)
{
lcd.setCursor(5, 1);
lcd.print(" ");
min = 0;
hora++;
}

if(hora == 24){
hora = 0;
}

lcd.setCursor(2, 0);
lcd.print(hora);
lcd.setCursor(4, 0);
lcd.print("h");
delay(100);
lcd.setCursor(0, 1);
lcd.print(min);
lcd.setCursor(2, 1);
lcd.print("m");
delay(100);
lcd.setCursor(5, 1);
lcd.print(sec);
lcd.setCursor(7, 1);
lcd.print("s");
delay(100);
}
if(estadoBotao1 == HIGH){
while(estadoBotao2 == LOW){
sec = 0;
min = 0;
hora = 0;
zero = 0;
lcd.clear();
}
}
}
}

Try here

1 Like

Forget that, focus in this new one

OK.
Can we expect code tags any time soon?

(What was wrong with the other topic?)

That’s the matter for a new topic

Yeah. Cross-posting. That's a bad choice.