So you work in your cubicle and knowing the hour is an important deal for commuting. What about a retro 7 segment clock for your desk? And can we add auto time adjustment? Sure we can and it is not complicated.
1. NodeMCU
1. 7 Segment Display
ConnectionsInclude the following libraries
#include <Arduino.h>
#include <TM1637Display.h>
#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
#define CLK D2
#define DIO D3
#define TEST_DELAY 100
TM1637Display display(CLK, DIO);
Setup section
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( "." );
}
timeClient.begin();
// Set offset time in seconds to adjust for your timezone, for example:
// GMT +1 = 3600
// GMT +8 = 28800
// GMT -1 = -3600
// GMT 0 = 0
timeClient.setTimeOffset(-10800);
Loop section
timeClient.update();
uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
display.setBrightness(0x0f);
completeHour=timeClient.getHours()*100;
completeHour=completeHour+timeClient.getMinutes();
display.showNumberDec(completeHour, false,4);
delay(5000);
Complete source code can be found in this link for free with Kindle Unlimited
Comments