#include <TM1637Display.h>
#define I2C_ADDR 0x27
/* ======== USER SETTINGS =========== */
// special effects
#define ENABLE_TICK_SOUND true
// Define the connections pins for display
#define CLK 6
#define DIO 7
#define LED 0
// Define other pin connections
#define BUZZER 9
int duration; // Duration in seconds - 30
// Create display object of type TM1637Display:
TM1637Display display = TM1637Display(CLK, DIO);
// Set the individual segments for the word displays:
const uint8_t seg_end[] = {
SEG_A | SEG_D | SEG_E | SEG_F | SEG_G, // E
SEG_C | SEG_E | SEG_G, // n
SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // d
0x00 // All off
};
const uint8_t seg_go[] = {
SEG_A | SEG_B | SEG_C | SEG_D | SEG_F | SEG_G,// g
SEG_C | SEG_D | SEG_E | SEG_G, // o
0x00, // All off
0x00 // All off
};
void setup() {
pinMode(BUZZER, OUTPUT);
pinMode(LED, OUTPUT);
display.setBrightness(2); // 0 to 7 change if required
ShowTime(30);
}
void loop() {
ShowTime(717);
digitalWrite(LED, HIGH);
//TimeDuration(30);
digitalWrite(LED, LOW);
delay(10000);
}
void TimeDuration(int duration) {
// While loop will continue until time up
unsigned long startTime = millis();
unsigned long timer = 1000 * duration;
// Repeatedly check if time is up
while ((millis() - startTime) <= timer) {
// Calculate time elapsed in seconds
int elapsed = int((millis() - startTime) / 1000);
// Only start to display countdown after 3 seconds
if ((millis() - startTime) > 0000) {
ShowTime(duration - elapsed);
tone(BUZZER, 1300, 150);
delay(1000);
}
}
display.clear();
// display.setSegments(seg_end);
// Wait 5 seconds and reset display
// delay(5000);
// Show duration for next player
ShowTime(duration);
}
// void ShowTime(int value) {
// static int lastTime;
// // Update the display if time has changed
// if (lastTime != value) {
// lastTime = value;
// int iSeconds = value;
// // Show on 4 digit display
// uint16_t number = iSeconds;
// display.showNumberDecEx(number, 0b01000000, true, 4, 0);
// }
// }
void ShowTime(int value){
static int lastTime;
// Update the display if time has changed
if (lastTime != value) {
lastTime = value;
int iMinutes = value / 60;
int iSeconds = value - (iMinutes * 60);
// Show on 4 digit display
uint16_t number = iMinutes * 100 + iSeconds;
display.showNumberDecEx(number, 0b01000000, true, 4, 0);
}
}