#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x27, 16, 2);
unsigned long tAwal, tSaatini, dataSW;
unsigned long tAwal2, tSaatini2, dataSW2;
bool count = false;
bool count2 = false;
void setup() {
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
lcd.init();
lcd.backlight();
lcd.setCursor(2, 0);
lcd.print("Tekan Tombol");
lcd.setCursor(2, 1);
lcd.print("Start / Stop");
delay(1000);
lcd.clear();
}
void loop() {
if (digitalRead(2) == 0) {
tAwal = millis() - dataSW;
count = true;
lcd.setCursor(0, 0);
lcd.print("STR1");
}
else if (digitalRead(3) == 0) {
count = false;
lcd.setCursor(0, 0);
lcd.print("STP1");
}
else if (digitalRead(4) == 0){
tAwal2 = millis() - dataSW2;
count2 = true;
lcd.setCursor(0, 1);
lcd.print("STR2");
}
else if (digitalRead(5) == 0) {
count2 = false;
lcd.setCursor(0, 1);
lcd.print("STP2");
}
else if (digitalRead(6) == 0) {
count = false;
count2 = false;
dataSW = 0;
dataSW2 = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Reset Stopwatch");
lcd.setCursor(4, 1);
lcd.print("0:0:0:0");
delay(1000);
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("Tekan Tombol");
lcd.setCursor(2, 1);
lcd.print("Start / Stop");
delay(1000);
lcd.clear();
}
if (count) {
tSaatini = millis();
dataSW = tSaatini - tAwal;
float jam, mnt, dtk, ms;
unsigned long over;
jam = int(dataSW / 3600000);
over = dataSW % 3600000;
mnt = int(over / 60000);
over = over % 60000;
dtk = int(over / 1000);
ms = over % 1000;
lcd.setCursor(5, 0);
lcd.print(jam, 0);
lcd.print(":");
lcd.print(mnt, 0);
lcd.print(":");
lcd.print(dtk, 0);
lcd.print(":");
lcd.print(ms, 0);
lcd.print(" ");
}
if (count2) {
tSaatini2 = millis();
dataSW2 = tSaatini2 - tAwal2;
float jam2, mnt2, dtk2, ms2;
unsigned long over2;
jam2 = int(dataSW2 / 3600000);
over2 = dataSW2 % 3600000;
mnt2 = int(over2 / 60000);
over2 = over2 % 60000;
dtk2 = int(over2 / 1000);
ms2 = over2 % 1000;
lcd.setCursor(5, 1);
lcd.print(jam2, 0);
lcd.print(":");
lcd.print(mnt2, 0);
lcd.print(":");
lcd.print(dtk2, 0);
lcd.print(":");
lcd.print(ms2, 0);
lcd.print(" ");
}
}