#include <WiFi.h>
#include <time.h>
#include <TM1637Display.h>
// Define the pins for TM1637 display
#define CLK_PIN 4 // CLK pin of the TM1637 display connected to digital pin 4
#define DIO_PIN 5 // DIO pin of the TM1637 display connected to digital pin 5
TM1637Display display(CLK_PIN, DIO_PIN);
// Replace with your network credentials
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// Set the time (year, month, day, hour, minute, second) in UTC
const tm timeInfo = {
2024 - 1900, // year
1 - 1, // month (0 - 11)
22, // day
12, // hour
0, // minute
0 // second
};
void printLocalTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("Failed to obtain time");
return;
}
int hour = timeinfo.tm_hour;
int minute = timeinfo.tm_min;
// Print hour on the left 2 digits and minute on the right 2 digits
display.showNumberDecEx(hour * 100 + minute, 0b11110000, true);
}
void setup() {
// Start serial communication
Serial.begin(115200);
// Initialize the TM1637 display
display.setBrightness(0x0f); // set the brightness to maximum
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
Serial.print('.');
}
Serial.println();
// Set the system time using configTzTime
configTzTime("IST-5:30", "pool.ntp.org");
Serial.println("Waiting for time to be set...");
while (time(nullptr) < 1510644967) {
delay(500);
Serial.print('.');
}
Serial.println();
Serial.println("Time set successfully");
}
void loop() {
// Print the current time on the TM1637 display
printLocalTime();
// Add your code here to perform actions based on the current time
// Delay for 1 minute
delay(60000);
}