// Stefius Klimakiste
// Version 1.0 09.12.22
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// AHT10/20
#include <Adafruit_AHTX0.h>
Adafruit_AHTX0 aht;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Trendvariablen
int trent_x = 0;
int trent_n = 30;
float temp_trent;
float hydr_trent;
float temp_t;
float hydr_t;
float temp_t2;
float hydr_t2;
char temp_txt[8];
char hydr_txt[8];
int balken = 0;
// INput
int Taster = 2;
int Taster_status = 0;
void setup() {
Wire.begin(); // i2c bus
Serial.begin(9600); // serial
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;)
;
}
display.display();
// Lösche Anzeige
display.clearDisplay();
if (!aht.begin()) {
Serial.println("Kein Geber AHT? Check");
delay(10);
}
Serial.println("AHT10 oder AHT20 nicht da");
// Interupt aufrufen
attachInterrupt(digitalPinToInterrupt(Taster), tasters, RISING);
}
void tasters() {
Taster_status = 1;
}
void loop() {
// Sensor AHT 10/20
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);
temp_trent = temp_trent + temp.temperature;
hydr_trent = hydr_trent + humidity.relative_humidity;
trent_x++;
if (trent_x == trent_n) {
// Durchschnitt
temp_t2 = round(temp_trent / trent_n);
hydr_t2 = round(hydr_trent / trent_n);
strcpy(temp_txt, "=");
strcpy(hydr_txt, "=");
if (temp_t > temp_t2) {
strcpy(temp_txt, "\x1F");
}
if (temp_t < temp_t2) {
strcpy(temp_txt, "\x1E");
}
if (hydr_t > hydr_t2) {
strcpy(hydr_txt, "\x1F");
}
if (hydr_t < hydr_t2) {
strcpy(hydr_txt, "\x1E");
}
trent_x = 0;
temp_trent = temp_t = temp_t2;
hydr_trent = hydr_t = hydr_t2;
display.cp437(true);
display.fillRect(0, 22, 128, 17, BLACK);
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 22);
display.print(String(temp_txt));
display.setCursor(116, 22);
display.print(String(hydr_txt));
display.setCursor(30, 22);
display.setTextSize(1);
display.print("Trent");
display.display();
}
balken = round(128 / trent_n * trent_x);
display.fillRect(0, 17, 128, 2, BLACK);
display.fillRect(0, 17, balken, 2, WHITE);
display.display();
if (trent_x % 2 == 0) {
display.fillRect(30, 22, 85, 10, BLACK);
display.setCursor(30, 24);
display.setTextSize(1);
display.print("Trent");
} else {
display.fillRect(30, 22, 85, 10, BLACK);
display.setCursor(30, 24);
display.setTextSize(1);
display.print("Klimakiste");
}
if (Taster_status == 1) {
display.cp437(true);
display.fillRect(0, 0, 128, 32, BLACK);
display.setTextSize(3);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print(" " + String(temp.temperature, 1) + "\xF8" + "C ");
display.display();
delay(800);
display.fillRect(0, 0, 128, 32, BLACK);
display.setTextSize(3);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print(" " + String(humidity.relative_humidity, 1) + "%");
display.display();
delay(1200);
display.fillRect(0, 0, 128, 32, BLACK);
display.display();
Taster_status = 0;
} else {
display.cp437(true);
display.fillRect(0, 0, 128, 17, BLACK);
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print(String(temp.temperature, 1) + "\xF8" + "C ");
display.setCursor(90, 0);
display.print(String(humidity.relative_humidity, 0) + "% ");
display.display();
delay(2000);
}
}