#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define LCD_ADDR 0x27
#define BUTTON_PIN 9
#define ADD_BUTTON_PIN 4

LiquidCrystal_I2C lcd(LCD_ADDR, 16, 2);

unsigned long lastButtonPressTime = 0;
unsigned long lastAddButtonPressTime = 0;
unsigned int buttonPressCount = 0;
unsigned int totalJobsDone = 0;

void setup() {
  lcd.begin(16, 2);
  lcd.backlight();
  
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(ADD_BUTTON_PIN, INPUT_PULLUP);
}

void loop() {
  unsigned long currentTime = millis();

  // Check if the button is pressed
  if (digitalRead(BUTTON_PIN) == LOW) {
    if (currentTime - lastButtonPressTime >= 200) {
      buttonPressCount++;
      lastButtonPressTime = currentTime;
    }
  }

  // Check if the add button is pressed
  if (digitalRead(ADD_BUTTON_PIN) == LOW) {
    if (currentTime - lastAddButtonPressTime >= 2000) {
      totalJobsDone += buttonPressCount;
      buttonPressCount = 0;
      lastAddButtonPressTime = currentTime;
    }
  }

  // Check if more than a minute has passed without button press
  if (currentTime - lastButtonPressTime >= 60000) {
    buttonPressCount = 0;
  }

  // Display counts on the LCD
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Job Cout: " + String(buttonPressCount));
  lcd.setCursor(0, 1);
  lcd.print("Total Jobs: " + String(totalJobsDone));

  delay(100); // Adjust delay based on your needs
}