//Hier werden die notwendigen Bibliotheken für die I2C-Kommunikation,
// das LCD-Display und das RTC-Modul importiert.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
#include <DHT.h>
#define DHTPIN 4
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
#include <TM1637.h>
int CLK = 5;
int DIO = 6;
TM1637 SSDx4(CLK, DIO);
// Es werden Objekte für die DS1307 RTC und das I2C-LCD-Display erstellt.
// lcd mit der Adresse 0x27, 16 Spalten und 2 Zeilen initialisiert.
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
// Initialisiere die serielle Kommunikation für Debug-Ausgaben
Serial.begin(9600);
// Initialisiere die I2C-Kommunikation und das LCD-Display
Wire.begin();
lcd.init(); // lcd.begin(16, 4);
lcd.backlight( ) ;
dht.begin();
SSDx4.init(); SSDx4.set(5);
// Überprüfe, ob die RTC korrekt initialisiert werden kann
if (!rtc.begin()) {
Serial.println("RTC konnte nicht gefunden werden");
while (1); // Bleibe in einer Endlosschleife, wenn die RTC nicht gefunden wird
}
// Überprüfe, ob die RTC läuft. Falls nicht, setze die Zeit auf die Kompilierungszeit
if (!rtc.isrunning()) {
Serial.println("RTC läuft NICHT!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void Seriell( float Temp, float humidity ) {
// Check if any reads failed and exit early (to try again).
if (isnan(Temp) || isnan( humidity )) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
Serial.print( Temp );
Serial.println(F("°C "));
// Wait a few seconds between measurements.
//delay(2000);
}
void loop() {
// Lese die aktuelle Zeit von der RTC
DateTime now = rtc.now();
// Lösche das LCD-Display
//lcd.clear();
// Setze den Cursor auf die erste Zeile und gib das Datum aus
lcd.setCursor(0, 0);
lcd.print("Datum: ");
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);
lcd.print(" ");
// Setze den Cursor auf die zweite Zeile und gib die Uhrzeit aus
lcd.setCursor(0, 1);
lcd.print("Uhrzeit: ");
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.print(" ");
float temp = dht.readTemperature();
float hum = dht.readHumidity();
lcd.setCursor(0, 2);
lcd.print("T: "); lcd.print( temp, 1);
lcd.print(" RH/%="); lcd.print( hum, 1);
lcd.print(" ");
// Warte für eine Sekunde
Seriell( temp, hum );
/* SSDx4.display(0, 1); SSDx4.display(1, 3);
SSDx4.point(1);
SSDx4.display(2, 3); SSDx4.display(3, 7); */
SSDx4.display(0, now.minute()/10);
SSDx4.display(1, now.minute()%10);
SSDx4.point(1);
SSDx4.display(2, now.second()/10);
SSDx4.display(3, now.second()%10);
delay(1000);
}