#include <TM1637Display.h>
#include <Wire.h>

const int CLK_PIN = A5;
const int DIO_PIN = A4;
const int startStopPin = 2;
const int resetPin = 3;

TM1637Display display(CLK_PIN, DIO_PIN);

volatile boolean isRunning = false;
unsigned long startTime = 0;
unsigned long elapsedTime = 0;

void setup() {
  display.setBrightness(0x0f);
  pinMode(startStopPin, INPUT_PULLUP);
  pinMode(resetPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(startStopPin), startStopInterrupt, CHANGE);
  attachInterrupt(digitalPinToInterrupt(resetPin), resetInterrupt, FALLING);
}

void loop() {
  if (isRunning) {
    elapsedTime = millis() - startTime;
  }

  unsigned int minutes = (elapsedTime / 60000) % 60;
  unsigned int seconds = (elapsedTime / 1000) % 60;

  display.showNumberDecEx(minutes * 100 + seconds, 0b01000000, true);

  delay(200);
}

void startStopInterrupt() {
  if (digitalRead(startStopPin) == LOW) {
    if (isRunning) {
      isRunning = false;
    } else {
      isRunning = true;
      startTime = millis() - elapsedTime;
    }
  }
}

void resetInterrupt() {
  if (digitalRead(resetPin) == LOW) {
    elapsedTime = 0;
  }
}
4-Digit Display