#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define buttonPin 2
#define potPin A0
#define LED 9
LiquidCrystal_I2C lcd(0x27, 16, 2);
int countdownTime = 0;
unsigned long startTime = 0;
bool countdownStarted = false;
void setup() {
lcd.init();
lcd.backlight();
pinMode(buttonPin, INPUT_PULLUP);
pinMode(LED, OUTPUT);
}
void loop() {
int potValue = map(analogRead(potPin), 0, 1023, 1, 600);
lcd.setCursor(0, 0);
lcd.print("Szamlalas: ");
lcd.print(potValue);
lcd.print("s ");
if (digitalRead(buttonPin) == LOW && !countdownStarted) {
countdownTime = potValue;
startTime = millis();
countdownStarted = true;
}
if (countdownStarted) {
int remainingTime = countdownTime - (millis() - startTime) / 1000;
lcd.setCursor(0, 1);
lcd.print("Hatralevo: ");
lcd.print(remainingTime);
lcd.print("s ");
if (remainingTime <= 0) {
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
countdownStarted = false;
}
}
}