#include <TM1637Display.h>
// Countdown Timer
const unsigned long COUNTDOWN_TIME = 5; // 5 minutes in seconds = 3--
// Pins for TM1637 display module
#define CLK_PIN 2
#define DIO_PIN 3
int RELAY1 = 8; //POWER RELAY
TM1637Display display(CLK_PIN, DIO_PIN);
unsigned long startTime;
unsigned long currentTime;
unsigned long elapsedTime;
void setup() {
pinMode(RELAY1, OUTPUT);
pinMode(RELAY1, LOW); //light is OFF
Serial.begin(9600);
display.setBrightness(7); // Set the brightness of the display (0-7)
display.clear(); // Clear the display
startTime = millis(); // Record the starting time
}
void loop() {
currentTime = millis(); // Get the current time
elapsedTime = (currentTime - startTime) / 1000; // Calculate elapsed time in seconds
if (elapsedTime <= COUNTDOWN_TIME) {
digitalWrite(RELAY1, HIGH); //lights ON
unsigned long remainingTime = COUNTDOWN_TIME - elapsedTime;
// Display remaining time in Minutes:Seconds format
unsigned int minutes = remainingTime / 60;
unsigned int seconds = remainingTime % 60;
display.showNumberDecEx(minutes * 100 + seconds, 0b01000000, true);
Serial.print("TIME: ");
Serial.println(elapsedTime);
if (remainingTime == 0) {
// Start blinking when countdown reaches 00:00
while (true) {
//digitalWrite(RELAY1, HIGH); //lights ON
digitalWrite(RELAY1, LOW); //lights OFF
// Serial.print("REAMAINING: ");
// Serial.println(elapsedTime);
display.showNumberDecEx(0, 0b01000000, true); // Display "00:00"
delay(500);
display.clear(); // Clear the display
delay(500);
Serial.print(elapsedTime);
//input Ultrasonic here again
exit(0);
return loop();
}
}
}
delay(1000); // Wait for 1 second
}