#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHTesp.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1 // Reset pin (or -1 if sharing Arduino reset pin)
#define OLED_ADDR 0x3C // Most common I2C OLED address
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define DHTPIN 7
DHTesp dht;
void setup() {
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
} else {
Serial.println(F("SDD1306 allocation succeeded"));
}
dht.setup(DHTPIN, DHTesp::AUTO_DETECT);
}
void loop() {
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
rotationAngleX += 0.05; // Rotate around X-axis
rotationAngleY += 0.010; // Rotate around Y-axis
rotationAngleZ += 0.075; // Rotate around Z-axis
drawCube();
display.setTextSize(1);
display.setCursor(0,0);
display.println("Weather");
display.setTextSize(1);
display.setCursor(0,8*2);
display.println(String("69") + "c");
display.println(String("69") + "%");
display.setTextSize(1);
display.setCursor(127 - ((4 * 6) * 1), 0);
display.println("Room");
display.setTextSize(1);
float temperature = (analogRead(A0) * (5.0 / 1023.0) * 100);
String temp = String((dht.getTemperature() + temperature) / 2) + "c";
String humi = String(dht.getHumidity()) + "%";
display.setCursor(127 - ((temp.length() * 6) * 1),8*2);
display.println(temp);
display.setCursor(127 - ((humi.length() * 6) * 1), 8*3);
display.println(humi);
display.display();
}