// Define the LED pin and reset pin
const int ledPin = 13;
const int resetPin = 2; // Button connected to pin 2 (for manual reset)
// Define the starting countdown time in seconds
int countdownTime = 5; // 60 seconds
void setup() {
// Initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
// Initialize the reset pin as an input with internal pull-up resistor
pinMode(resetPin, INPUT_PULLUP); // Button press will trigger a reset
// Start serial communication for debugging
Serial.begin(9600);
}
void loop() {
// Check if countdownTime is greater than 0
if (countdownTime > 0) {
// Print the countdown value to the Serial Monitor
Serial.print("Time remaining: ");
Serial.println(countdownTime);
// Decrease the countdown value by 1
countdownTime = countdownTime - 1;;
// Wait for 1 second before continuing the countdown
delay(1000); // Delay for 1000 milliseconds (1 second)
}
else {
// Once countdown reaches 0, turn on the LED
digitalWrite(ledPin, HIGH);
// Print a message indicating the LED is on
Serial.println("Countdown complete! LED ON.");
// Wait for 5 seconds before resetting the countdown automatically
delay(5000); // Delay for 5000 milliseconds (5 seconds)
// Reset the countdown to 60 seconds after 5 seconds
countdownTime = 5;
// Turn off the LED after the reset
digitalWrite(ledPin, LOW);
// Print a message indicating the countdown has been reset
Serial.println("Countdown reset to 5 seconds.");
}
// If the button connected to resetPin is pressed, reset the countdown manually
if (digitalRead(resetPin) == LOW) {
countdownTime = 60;
digitalWrite(ledPin, LOW); // Turn off LED when reset
Serial.println("Countdown manually reset to 5 seconds.");
delay(500); // Delay to debounce the button
}
}