// Youtube : OPTI MIST
// Go with this link :[Link]
#include <TM1637Display.h>
// Pins for the tm1637 display module
#define CLK 7
#define DIO 8
// Pins for the push buttons
#define START_STOP_BUTTON_PIN A0
#define RESET_BUTTON_PIN A1
int kuning = 4;
int buz = 5;
int hijau = 6;
int merah = 11;
TM1637Display display(CLK, DIO);
unsigned long waktumulai = 0;
unsigned long waktusaatini = 0;
unsigned long waktuberlalu = 0;
boolean sedangberjalan = false;
void setup() {
pinMode (kuning, OUTPUT);
pinMode (hijau, OUTPUT);
pinMode (merah, OUTPUT);
pinMode (buz, OUTPUT);
[Link](0x0f);
pinMode(START_STOP_BUTTON_PIN, INPUT_PULLUP);
pinMode(RESET_BUTTON_PIN, INPUT_PULLUP);
}
void loop() {
// Check if the start/stop button has been pressed
if (digitalRead(START_STOP_BUTTON_PIN) == LOW) {
delay(20); // menghilangkan bouncing
if (digitalRead(START_STOP_BUTTON_PIN) == LOW) {
digitalWrite(hijau, HIGH);
// Button is pressed
if (!sedangberjalan) {
// Start the stopwatch
waktumulai = millis() - waktuberlalu;
sedangberjalan = true;
} else {
// Stop the stopwatch
sedangberjalan = false;
waktuberlalu = millis() - waktumulai;
}
}
}
// Check if the reset button has been pressed
if (digitalRead(RESET_BUTTON_PIN) == LOW) {
delay(20); // debounce
if (digitalRead(RESET_BUTTON_PIN) == LOW) {
digitalWrite(kuning, LOW);
digitalWrite(hijau, LOW);
digitalWrite(merah, LOW);
// Button is pressed
waktuberlalu = 0;
sedangberjalan = false;
}
}
// Calculate the elapsed time
if (sedangberjalan) {
waktusaatini = millis();
waktuberlalu = waktusaatini - waktumulai;
}
// Display the elapsed time
int seconds = waktuberlalu / 1000;
int minutes = seconds / 60;
int detikSisa = seconds % 60;
int waktutampil = minutes * 100 + detikSisa;
[Link](waktutampil, 0b01000000, true);
if (waktutampil == 120) { // Mulai berkedip ketika hitungan mencapai 02:00
while (true) {
digitalWrite(merah, HIGH);
digitalWrite(buz, HIGH);
[Link](waktutampil *100 /60 , 0b01000000, true);
delay(1000);
digitalWrite(buz, LOW);
[Link](); // Clear the display
delay(500);
}
}