#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int bt1 = 27;
int bt2 = 26;
int contador = 0;
bool contando = false;
unsigned long tempo = 0;
void setup() {
pinMode(bt1, INPUT_PULLUP);
pinMode(bt2, INPUT_PULLUP);
lcd.init();
lcd.backlight();
}
void loop() {
if (digitalRead(bt2) == LOW) {
contador = 0;
contando = false;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Resetado");
delay(200);
return;
}
if (digitalRead(bt1) == LOW) {
contando = true;
delay(200);
}
if (contando && millis() - tempo >= 1000) {
tempo = millis();
contador++;
if (contador > 9) contador = 0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Contando:");
lcd.setCursor(0,1);
lcd.print(contador);
}
if (!contando) {
lcd.setCursor(0,0);
lcd.print("Parado ");
lcd.setCursor(0,1);
lcd.print(contador);
}
}