#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#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);
float voltage = 220.0; // Voltage value
float current = 5.0; // Current value
float power = 500.0; // power value
float energy = 10.0; // Energy value
void setup() {
Serial.begin(9600);
// 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
}
void loop() {
// In a real-world scenario, you would update the voltage and current values here
// For demonstration purposes, we will keep them static
// Display voltage and current values
updateDisplay();
// Add some delay before updating the display again
delay(1000); // You can adjust this delay according to your needs
}
void updateDisplay() {
oled.clearDisplay(); // Clear the display
oled.setCursor(0, 2); // Set cursor position
// Print voltage value
oled.print("Voltage=");
oled.print(voltage);
oled.println("V ");
oled.println("");
// Print current value
oled.print("Current=");
oled.print(current);
oled.println("A");
oled.println("");
// Print current value
oled.print("Power=");
oled.print(power);
oled.println("kW");
oled.println("");
// Print current value
oled.print("Energy=");
oled.print(energy);
oled.println("kW/h");
oled.println("");
oled.display(); // Display on OLED
}