Hi please can someone help me,
i am trying to display a clock on my oled but unfortunately struggling.
here is the code that i would like to display. i can serial print and it looks fine but how can i write it to my oled display.
Many Thanks Gareth
#include <WiFi.h>
#include "time.h"
#include "SSD1306Wire.h"
SSD1306Wire display(0x3c, 5, 4);
const char* ssid = "AndroidAP";
const char* password = "vaze1985";
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 0;
const int daylightOffset_sec = 0;
void printLocalTime()
{
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
return;
}
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S"); // this is the line i want to print to my oled
display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawStringMaxWidth(0, 0, 128,"DISPLAY THE TIME HERE" ); // HOW DO I PUT IT HERE
display.display();
delay(1000);
delay(1000);
}
void setup()
{
Serial.begin(115200);
display.init();
//connect to WiFi
Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(" CONNECTED");
//init and get the time
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
printLocalTime();
//disconnect WiFi as it's no longer needed
WiFi.disconnect(true);
WiFi.mode(WIFI_OFF);
}
void loop()
{
delay(1000);
printLocalTime();
}