#include "SevSeg.h"

SevSeg sevseg;

int count = 0;
const int countMax = 9999;  // Maximum count value

void setup() {
  pinMode(A0, INPUT_PULLUP); // Set Pin A0 as input with pull-up resistor
  pinMode(A1, INPUT_PULLUP); // Set Pin A1 as input with pull-up resistor

  byte numDigits = 4;
  //10 is digit 1, 11 is digit 2, 12, is digit 3, 13 is digit 4 
  byte digitPins[] = {10, 11, 12, 13};
  // 9is A,2 is B,3 is C, 4 is D, 5 is D,6 is E,7 is G,8 is F
  byte segmentPins[] = {9, 2, 3, 5, 6, 8, 7, 4};
  bool resistorsOnSegments = true;
  bool updateWithDelays = true;  // Set to true for smooth transitions
  byte hardwareConfig = COMMON_CATHODE;

  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
  sevseg.setBrightness(90);

  // Initialize the display with "0000"
  sevseg.setChars("0000");
  sevseg.refreshDisplay();
}

void loop() {
  // Check if Pin A0 is LOW (count up)
  if (digitalRead(A0) == LOW) {
    delay(100);  // Debounce
    if (count < countMax) {
      count++;
    }
  }

  // Check if Pin A1 is LOW (count down)
  if (digitalRead(A1) == LOW) {
    delay(100);  // Debounce
    if (count > 0) {
      count--;
    }
  }

  // Display the count with leading zeros
  char countString[5];
  sprintf(countString, "%04d", count);
  sevseg.setChars(countString);
  sevseg.refreshDisplay();
}