#include "Arduino.h"
#include <TM1637Display.h>
const int CLK = 2; // Define CLK pin for TM1637 display
const int DIO = 3; // Define DIO pin for TM1637 display
const int ledPin = 13; // Define LED pin
const int buzzerPin = 8; // Define Buzzer pin
const int buttonPin = 7; // Define Button pin
TM1637Display display(CLK, DIO);
int countdown = 30; // Initial countdown value in seconds
bool countdownActive = false;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
display.setBrightness(0x0a); // Set the brightness of the display (0x00 to 0x0f)
}
void loop() {
if (digitalRead(buttonPin) == LOW && !countdownActive) {
countdownActive = true;
startCountdown();
}
if (countdownActive) {
updateDisplay();
delay(1000); // Update every second
}
}
void startCountdown() {
for (int i = countdown; i >= 0; i--) {
countdown = i;
updateDisplay();
delay(1000);
if (i == 0) {
digitalWrite(ledPin, HIGH); // Turn on LED at pin 13
activateBuzzer();
delay(3000); // Buzzer and LED on for 3 seconds
digitalWrite(ledPin, LOW); // Turn off LED
deactivateBuzzer();
countdownActive = false;
}
}
}
void updateDisplay() {
int minutes = countdown / 60;
int seconds = countdown % 60;
display.showNumberDecEx((minutes * 100) + seconds, 0b11100000, true);
}
void activateBuzzer() {
tone(buzzerPin, 1000); // Activate the buzzer with a frequency of 1000 Hz
}
void deactivateBuzzer() {
noTone(buzzerPin); // Turn off the buzzer
}