m5paper_weather_display.ino

M5Stack M5Paper · Fichier : m5paper_weather_display.ino · Langage : C++ · Usage : Afficher l'heure actuelle mise à jour via le réseau NTP.

Combine Wi-Fi et l'écran e-Ink pour créer une horloge réseau simple.

Remplacez YOUR_SSID et YOUR_PASSWORD par vos identifiants. Utilise la bibliothèque NTPClient. L'écran ne doit pas être rafraîchi trop souvent pour éviter le 'ghosting' et économiser la batterie. Le mode profond peut être ajouté pour une autonomie maximale.

m5paper_weather_display.ino

#include <M5EPD.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#include <NTPClient.h>

M5EPD m5epd;
const char *ssid     = "YOUR_SSID";
const char *password = "YOUR_PASSWORD";

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 0, 60000);

void setup() {
  m5epd.begin();
  m5epd.updateBuffer();
  
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    m5epd.drawCentreString("Connecting...", 480, 270, 4);
    m5epd.updateDisplay();
  }
  
  timeClient.begin();
  timeClient.forceUpdate();
}

void loop() {
  timeClient.update();
  
  m5epd.fillScreen(EPD_WHITE);
  m5epd.drawCentreString(timeClient.getFormattedTime(), 480, 270, 8);
  m5epd.drawCentreString("M5Paper NTP Clock", 480, 350, 4);
  m5epd.updateDisplay();
  
  delay(10000); // Mise à jour toutes les 10 secondes
}

← Retour à la fiche