#include "stopwatch.h"
#define SW_DURATION 600
#define MAIN_DELAY 100
#define BUTTON_PIN 4
bool btn_locked = false;
void display_sw() {
char *sw = sw_display();
Serial.print("Remaining: ");
Serial.println(sw);
}
void setup() {
Serial.begin(115200);
Serial.println("Press the button to start ...");
pinMode(BUTTON_PIN, INPUT_PULLUP);
sw_init(SW_DURATION);
display_sw();
}
void loop() {
int value = digitalRead((BUTTON_PIN));
if (btn_locked && value == HIGH) {
btn_locked = false;
} else if (!btn_locked) {
if (value == LOW) {
btn_locked = true;
if (!sw_is_running()) {
sw_start();
} else {
sw_pause();
}
}
}
if (sw_update()) {
display_sw();
}
delay(MAIN_DELAY);
}