bal_gennady

Arduino clock with NOKIA 5110 LCD

Jan 15th, 2022 (edited)
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define OLED_RESET LED_BUILTIN // 4
  2. Adafruit_SSD1306 display(OLED_RESET);
  3.  
  4. const char *ssid = "имя сети";
  5. const char *password = "пароль от вай-фая";
  6.  
  7. int ledPin = 13;
  8.  
  9. int timezone = 7 * 3600;
  10. int dst = 0;
  11.  
  12. #if (SSD1306_LCDHEIGHT != 64)
  13. #error("Ошибка, пожалуйста исправте Adafruit_SSD1306.h!");
  14. #endif
  15.  
  16. void setup()
  17. {
  18.  
  19.     display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  20.     display.clearDisplay(); // Clear the buffer.
  21.     display.display();
  22.  
  23.     pinMode(ledPin, OUTPUT);
  24.     digitalWrite(ledPin, LOW);
  25.  
  26.     Serial.begin(115200);
  27.  
  28.     display.setTextSize(1);
  29.     display.setTextColor(WHITE);
  30.  
  31.     display.setCursor(0, 0);
  32.     display.println("Wifi connecting to ");
  33.     display.println(ssid);
  34.  
  35.     WiFi.begin(ssid, password);
  36.  
  37.     display.println("\nConnecting");
  38.  
  39.     display.display();
  40.  
  41.     while (WiFi.status() != WL_CONNECTED) {
  42.         delay(500);
  43.         display.print(".");
  44.         display.display();
  45.     }
  46.  
  47.     // Clear the buffer.
  48.     display.clearDisplay();
  49.     display.display();
  50.     display.setCursor(0, 0);
  51.     display.println("Wifi Connected!");
  52.     display.print("IP:");
  53.     display.println(WiFi.localIP());
  54.     display.display();
  55.     configTime(timezone, dst, "pool.ntp.org", "time.nist.gov");
  56.     display.println("\nWaiting for NTP...");
  57.     while (!time(nullptr)) {
  58.         Serial.print("*");
  59.         delay(1000);
  60.     }
  61.     display.println("\nTime response....OK");
  62.     display.display();
  63.     delay(1000);
  64.     display.clearDisplay();
  65.     display.display();
  66. }
  67.  
  68. void loop()
  69. {
  70.     time_t now = time(nullptr);
  71.     struct tm *p_tm = localtime(&now);
  72.     Serial.print(p_tm->tm_mday);
  73.     Serial.print("/");
  74.     Serial.print(p_tm->tm_mon + 1);
  75.     Serial.print("/");
  76.     Serial.print(p_tm->tm_year + 1900);
  77.     Serial.print(" ");
  78.     Serial.print(p_tm->tm_hour);
  79.     Serial.print(":");
  80.     Serial.print(p_tm->tm_min);
  81.     Serial.print(":");
  82.     Serial.println(p_tm->tm_sec);
  83.     // Clear the buffer.
  84.     display.clearDisplay();
  85.     display.setTextSize(3);
  86.     display.setTextColor(WHITE);
  87.     display.setCursor(0, 0);
  88.     display.print(p_tm->tm_hour);
  89.     display.print(":");
  90.     if (p_tm->tm_min < 10)
  91.         display.print("0");
  92.     display.print(p_tm->tm_min);
  93.     display.setTextSize(2);
  94.     display.setCursor(90, 5);
  95.     display.print(".");
  96.     if (p_tm->tm_sec < 10)
  97.         display.print("0");
  98.     display.print(p_tm->tm_sec);
  99.     display.setTextSize(1);
  100.     display.setCursor(0, 40);
  101.     display.print(p_tm->tm_mday);
  102.     display.print("/");
  103.     display.print(p_tm->tm_mon + 1);
  104.     display.print("/");
  105.     display.print(p_tm->tm_year + 1900);
  106.     display.display();
  107.     delay(1000); // Обновите каждые 1 сек
  108. }
Add Comment
Please, Sign In to add comment