const int runPin = 4;
const int resetPin = 2;
unsigned long run = 0;
unsigned long lastMillis = 0;
unsigned long detik = 0;
int resetState = 0;
int lastResetState =0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(runPin, INPUT_PULLUP);
pinMode(resetPin, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long currentMillis = millis();
unsigned long detik = (run / 1000);
resetState = digitalRead(resetPin);
if (digitalRead(runPin) == LOW) {
run += currentMillis - lastMillis;
Serial.println(detik);
}
if (resetState == LOW && lastResetState == HIGH) {
delay(50);
run = 0;
Serial.println("time reset!");
}
lastMillis = currentMillis;
lastResetState = resetState;
delay(500); // this speeds up the sim
}