#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <time.h>
// ---------- OLED setup ----------
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET -1
#define WIFI_ICON_X 110
#define WIFI_ICON_Y 0
const unsigned char wifi_icon_bits[] PROGMEM = {
// Example 8x8 pixel WiFi icon data (replace with your generated data)
//0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Top row (empty)
//0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Bottom row (empty)
// ... your actual WiFi icon bitmap data will go here ...
//0x00, 0x00, 0xff, 0xc0, 0xe1, 0xc0, 0x9c, 0xc0, 0xe3, 0xc0, 0xed, 0xc0, 0xf3, 0xc0, 0xff, 0xc0,
//0xff, 0xc0, 0x00, 0x00 // Example for a basic WiFi shape
0xe1, 0xc0, 0x80, 0x40, 0x1e, 0x00, 0x3f, 0x00, 0xe1, 0xc0, 0xc0, 0xc0, 0xcc, 0xc0, 0xff, 0xc0,
0xf3, 0xc0, 0xff, 0xc0
};
const unsigned char wifi_icon_disconnected[] PROGMEM = {
0x40, 0xc0, 0x80, 0x40, 0x2f, 0x00, 0xe1, 0xc0, 0xcc, 0xc0, 0xfe, 0xc0, 0xf3, 0x00, 0xff, 0xc0,
0xff, 0xc0, 0xff, 0xc0
};
#define WIFI_ICON_WIDTH 10
#define WIFI_ICON_HEIGHT 10
#define WIFI_SSID "Lyon Office"
Adafruit_SSD1306 displayTime(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 displayTemperature(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, OLED_RESET);
// ---------- Simulated data ----------
float simulatedTemp = -80.0;
bool wifiConnected = true;
unsigned long lastUpdate = 0;
unsigned long lastTempChange = 0;
// ---------- Draw WiFi icon ----------
void drawWiFiIcon(bool connected) {
displayTime.fillRect(WIFI_ICON_X, WIFI_ICON_Y, 18, 10, SSD1306_BLACK);
if (connected) {
//display.drawLine(WIFI_ICON_X + 2, 8, WIFI_ICON_X + 4, 4, SSD1306_WHITE);
//display.drawLine(WIFI_ICON_X + 4, 4, WIFI_ICON_X + 6, 8, SSD1306_WHITE);
//display.drawLine(WIFI_ICON_X + 7, 6, WIFI_ICON_X + 9, 8, SSD1306_WHITE);
displayTime.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, wifi_icon_bits, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, WHITE);
} else {
//display.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, wifi_icon_disconnected, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, WHITE);
displayTime.drawLine(WIFI_ICON_X + 6, 4, WIFI_ICON_X + 10, 8, SSD1306_WHITE);
displayTime.drawLine(WIFI_ICON_X + 6, 8, WIFI_ICON_X + 10, 4, SSD1306_WHITE);
}
}
// ---------- Display update ----------
void updateDisplay() {
displayTime.clearDisplay();
displayTime.setTextSize(1);
displayTime.setTextColor(SSD1306_WHITE);
displayTemperature.clearDisplay();
displayTemperature.setTextSize(2);
displayTemperature.setTextColor(SSD1306_WHITE);
// Current time
time_t now = millis() / 1000;
int hours = (now / 3600) % 24;
int mins = (now / 60) % 60;
int secs = now % 60;
char timeBuf[10];
sprintf(timeBuf, "%02d:%02d:%02d", hours, mins, secs);
displayTime.setTextSize(2);
displayTime.setCursor(6, 16);
displayTime.print(timeBuf);
drawWiFiIcon(wifiConnected);
// Top info Time display
displayTime.setTextSize(1);
displayTime.setCursor(0, 0);
displayTime.print(WIFI_SSID);
// Top line Temperature display
// Bottom info
displayTemperature.setTextSize(1);
displayTemperature.setCursor(0, 0);
displayTemperature.print("Temperature ");
displayTemperature.setCursor(72, 0);
displayTemperature.write(247);
displayTemperature.print("C:");
displayTime.setCursor(90, 52);
if (wifiConnected)
displayTime.print("OK");
else
displayTime.print("ERR");
displayTime.display();
// Temperature
displayTemperature.setTextSize(3);
displayTemperature.setCursor(0,12);
displayTemperature.printf("%.2f", simulatedTemp);
displayTemperature.display();
}
// ---------- Setup ----------
void setup() {
Serial.begin(115200);
Wire.begin();
if (!displayTime.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("OLED init failed!");
while (true);
}
displayTime.clearDisplay();
displayTime.display();
Serial.println("Time display OK.");
Wire1.begin(27,26);
if (!displayTemperature.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("OLED init failed!");
while (true);
}
displayTemperature.clearDisplay();
displayTemperature.display();
Serial.println("Temprature display OK.");
}
// ---------- Loop ----------
void loop() {
unsigned long now = millis();
// Update screen every second
if (now - lastUpdate > 1000) {
lastUpdate = now;
updateDisplay();
}
// Simulate slow temp drift and WiFi toggle every 10 seconds
if (now - lastTempChange > 10000) {
lastTempChange = now;
simulatedTemp += random(-3, 3);
if (simulatedTemp < -100) simulatedTemp = -90;
if (simulatedTemp > 50) simulatedTemp = 45;
wifiConnected = !wifiConnected;
}
}