#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <WiFi.h>
#define NTP_SERVER "europe.pool.ntp.org"
#define UTC_OFFSET 3600 // offset in milis, now it's set to UTC+1
#define UTC_OFFSET_DST 3600 // summer time change, if none: turn to 0
#define SCREEN_WIDTH 128 // OLED width, in pixels
#define SCREEN_HEIGHT 64 // OLED height, in pixels
// create an OLED display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(9600);
// WiFi
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
// initialize OLED display with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
delay(2000); // wait two seconds for initializing
oled.clearDisplay(); // clear display
oled.setTextSize(1); // set text size
oled.setTextColor(WHITE); // set text color
// wypełnienie
//testfillroundrect();
oled.display();
delay(2000);
//oled.clearDisplay(); // clear display
//oled.setCursor(20, 12); // text
//oled.setTextSize(2);
//oled.println("made by:");
//oled.setCursor(28, 30);
//oled.println("pio200");
//oled.display();
//delay(1000);
//oled.clearDisplay();
configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);
}
void loop() {
printLocalTime();
oled.display();
}
// I took oled.fillRoundRect function from Adafruit library
//void testfillroundrect(void) {
//uint8_t color = WHITE;
//for (int16_t i=0; i<SCREEN_HEIGHT/2-4; i+=2) {
//oled.fillRoundRect(i, i, SCREEN_WIDTH-2*i, SCREEN_HEIGHT-2*i, SCREEN_HEIGHT/4, color);
//if (color == WHITE) color = BLACK;
//else color = WHITE;
//oled.display();
//delay(50);
//}
//oled.setCursor(44, 28); // text
//oled.setTextSize(1);
//oled.println("Welcome!");
//}
void printLocalTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
oled.clearDisplay();
oled.setTextSize(2);
oled.setCursor(0, 16);
oled.println("ConnectionError");
return;
}
oled.clearDisplay();
oled.setTextSize(1);
oled.setCursor(15, 0);
oled.println("Küchenzeit");
oled.setTextSize(2);
oled.setCursor(12, 26);
oled.println(&timeinfo, "%H:%M:%S");
oled.setTextSize(1);
oled.setCursor(15, 50);
oled.println(&timeinfo, "%d %m %Y %Z");
}
//made by pio200