Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager/
- #include <Adafruit_SSD1306.h> // https://github.com/adafruit/Adafruit_SSD1306
- #include <Fonts/FreeMono9pt7b.h> // board: https://nl.aliexpress.com/item/1005006269242344.html
- #include <Fonts/FreeSansBold9pt7b.h>
- #include <Fonts/FreeSansBold18pt7b.h>
- WiFiManager myWiFi;
- Adafruit_SSD1306 oled(128, 64, &Wire, -1);
- uint8_t SCREEN_ORIENTATION = 2;
- char* timeZone = "CET-1CEST,M3.5.0,M10.5.0/3"; // https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv
- char* days[] = { "zondag", "maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag" };
- char* conn[] = { "WiFi: no connection.", "Connect to hotspot", "IDEA + open browser",
- "address 192.168.4.1", "to enter network name", "and password" };
- void setup() {
- oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
- oled.setRotation(SCREEN_ORIENTATION);
- oled.setTextColor(1); // white = 1, black = 0
- myWiFi.setAPCallback(messageNoConnection); // called when no WiFi connection is found
- myWiFi.autoConnect("IDEA");
- configTzTime(timeZone, "pool.ntp.org");
- }
- void loop() {
- struct tm tInfo; // https://cplusplus.com/reference/ctime/tm/
- getLocalTime(&tInfo);
- oled.clearDisplay();
- oled.setCursor(10, 25);
- oled.setFont(&FreeSansBold18pt7b);
- oled.printf("%02d:%02d", tInfo.tm_hour, tInfo.tm_min);
- oled.setFont(&FreeSansBold9pt7b);
- oled.printf(" %02d", tInfo.tm_sec);
- oled.setCursor(14, 45);
- oled.printf("%02d -%02d -%04d", tInfo.tm_mday, 1 + tInfo.tm_mon, 1900 + tInfo.tm_year);
- oled.setCursor(0, 60);
- oled.setFont(&FreeMono9pt7b);
- oled.setTextColor(0); // invisible because we just want to
- oled.print(days[tInfo.tm_wday]); // check the cursor x-position
- oled.setTextColor(1); // visible
- oled.setCursor((oled.width() - oled.getCursorX()) / 2, 60); // x-coordinate if we want to
- oled.print(days[tInfo.tm_wday]); // display the weekday centered
- oled.display();
- }
- void messageNoConnection(WiFiManager* myWiFi) { // called when no WiFi connection is found
- oled.clearDisplay();
- oled.setTextSize(1);
- for (uint8_t count = 0; count < 6; count++) {
- oled.setCursor(0, count * 10);
- oled.print(conn[count]);
- }
- oled.display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement