#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
const int buttonPin = 6;
const int buzzerPin = 5;
int buttonState = 0;
unsigned long startTime = 0;
bool timerRunning = false;
const unsigned long timerDuration = 11000;
void setup() {
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Press to start");
pinMode(buttonPin, INPUT);
pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin, LOW);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH && !timerRunning) {
startTime = millis();
timerRunning = true;
lcd.clear();
}
if (timerRunning) {
unsigned long elapsedTime = millis() - startTime;
if (elapsedTime >= timerDuration) {
timerRunning = false;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("0");
tone(buzzerPin, 1000);
delay(1000);
noTone(buzzerPin);
} else {
unsigned long remainingTime = (timerDuration - elapsedTime) / 1000;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(remainingTime);
}
}
delay(50);
}