From ee33513ab40875d706158949418b6d58379c6936 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Wed, 24 Jul 2019 16:04:41 +0200 Subject: [PATCH] display time --- src/main.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index a46dbcb..2926c1f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,6 +80,18 @@ void displayIcoPartial(const uint8_t bitmap[], uint16_t x, uint16_t y, uint16_t } +void getTime(char* ptr, size_t maxsize, const char* format) { + time_t now; + struct tm timeinfo; + time(&now); // update 'now' variable with current time + setenv("TZ", "CET-1CEST,M3.5.0/2,M10.5.0/3", 1); + tzset(); + localtime_r(&now, &timeinfo); + + strftime(ptr, maxsize, format, &timeinfo); +} + + void printValues() { #define SEALEVELPRESSURE_HPA (1013.25) Serial.print("Temperature = "); @@ -199,6 +211,13 @@ void loop() display.print("Luftdruck:"); display.print(bme.readPressure() / 100.0F); display.println(" hPa"); + + char timeStr[9]; + getTime(timeStr, sizeof(timeStr), "%H:%M:%S"); + display.setCursor(5, display.height()-5); + display.setFont(&Org_01); + display.print("Zeit: "); + display.println(timeStr); } while (display.nextPage()); display.powerOff();