#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
byte startstop = 2;
byte reset = 3;
bool szamol = false;
unsigned long start = 0;
unsigned long eltelt = 0;
int szamlalo = 0;
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
pinMode(startstop, INPUT_PULLUP);
pinMode(reset, INPUT_PULLUP);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 1);
lcd.print("Eltelt ido: (s)");
}
void loop() {
if (digitalRead(startstop) == LOW) {
delay(50);
if (!szamol) {
start = millis();
}
szamol = !szamol;
while (digitalRead(startstop) == LOW) {}
}
if (!szamol) {
if (digitalRead(reset) == LOW) {
delay(50);
szamlalo = 0;
lcd.setCursor(13, 1);
lcd.print(" ");
while (digitalRead(reset) == LOW) {}
}
}
if (szamol) {
unsigned long current = millis();
eltelt = (current - start) / 1000;
lcd.setCursor(13, 1);
lcd.print(eltelt);
}
delay(10);
}