Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. #include <WiFi.h>
  2. #include <NTPClient.h>
  3. #include <WiFiUdp.h>
  4.  
  5. #include <TFT_eSPI.h>
  6. #include <SPI.h>
  7.  
  8. #define TFT_BL          4  // Dispaly backlight control pin
  9.  
  10.  
  11. // Replace with your network credentials
  12. const char* ssid     = "";
  13. const char* password = "";
  14.  
  15. WiFiUDP ntpUDP;
  16. NTPClient timeClient(ntpUDP);
  17.  
  18. TFT_eSPI tft = TFT_eSPI();
  19.  
  20. void setup() {
  21.   if (TFT_BL > 0) {
  22.     pinMode(TFT_BL, OUTPUT);
  23.     digitalWrite(TFT_BL, HIGH);
  24.   }
  25.  
  26.   tft.init();
  27.   tft.setRotation(1);
  28.   tft.fillScreen(TFT_BLACK);
  29.  
  30.   tft.setTextColor(TFT_YELLOW, TFT_BLACK); // Note: the new fonts do not draw the background colour
  31.  
  32.   WiFi.begin(ssid, password);
  33.   while (WiFi.status() != WL_CONNECTED) {
  34.     delay(500);
  35.   }
  36.  
  37.   timeClient.begin();
  38.   timeClient.setTimeOffset(3600);
  39. }
  40. void loop() {
  41.   while(!timeClient.update()) {
  42.     timeClient.forceUpdate();
  43.   }
  44.   char timeString[25];
  45.   sprintf (timeString, "%i:%i:%i", timeClient.getHours (), timeClient.getMinutes (), timeClient.getSeconds ());
  46.  
  47.   tft.setTextColor(0x39C4, TFT_BLACK);  // Leave a 7 segment ghost image, comment out next line!
  48.   tft.drawString("88:88:88",10,10,7); // Overwrite the text to clear it
  49.   tft.setTextColor(0xFBE0, TFT_BLACK); // Orange
  50.   tft.drawString (timeString, 10, 10, 7);
  51.   delay(1000);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement