/************************************************************************************************* PROGRAMMINFO ************************************************************************************************** Funktion: MAX7229 RTC Uhr, DS1307 und DTH11 * for more examples: * https://github.com/MajicDesigns/MD_Parola/tree/main/examples * https://github.com/MajicDesigns/MD_MAX72XX/tree/main/examples ************************************************************************************************** Version: 29.12.2022 ************************************************************************************************** Board: UNO ************************************************************************************************** Libraries: https://majicdesigns.github.io/MD_MAX72XX/functions.html https://github.com/MajicDesigns/MD_MAX72XX/tree/main/examples https://github.com/espressif/arduino-esp32/tree/master/libraries C:\Users\User\Documents\Arduino D:\gittemp\Arduino II\A156_Wetterdaten_V3 ************************************************************************************************** C++ Arduino IDE V1.8.19 ************************************************************************************************** Einstellungen: https://dl.espressif.com/dl/package_esp32_index.json http://dan.drown.org/stm32duino/package_STM32duino_index.json http://arduino.esp8266.com/stable/package_esp8266com_index.json **************************************************************************************************/ #include #include #include #include #include #include "Font7Seg.h" // Hardware: //#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW #define HARDWARE_TYPE MD_MAX72XX::FC16_HW #define MAX_DEVICES 4 // Anzahl der Displays #define CLK_PIN 13 // CLK / SCK #define DATA_PIN 11 // DATA / MOSI #define CS_PIN 10 // CS / SS #define SPEED_TIME 75 // Speed #define PAUSE_TIME 0 #define MAX_MESG 20 // RTC Adresse #define DS1307_ADDRESS 0x68 // DHT #define DHTPIN 2 #define DHTTYPE DHT11 #define TIMEDHT 1000 // Variablen uint8_t wday, mday, month, year; uint8_t hours, minutes, seconds; char szTime[9]; // mm:ss\0 char szMesg[MAX_MESG + 1] = ""; float humidity, celsius, fahrenheit; uint8_t degC[] = { 6, 3, 3, 56, 68, 68, 68 }; // Deg C uint8_t degF[] = { 6, 3, 3, 124, 20, 20, 4 }; // Deg F uint8_t clear = 0x00; uint32_t timerDHT = TIMEDHT; DHT dht(DHTPIN, DHTTYPE); // SPI Verbindung MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES); void beginDS1307() { // RTC Daten Wire.beginTransmission(DS1307_ADDRESS); Wire.write(clear); Wire.endTransmission(); Wire.requestFrom(DS1307_ADDRESS, 0x07); seconds = bcdToDec(Wire.read()); minutes = bcdToDec(Wire.read()); hours = bcdToDec(Wire.read() & 0xff); wday = bcdToDec(Wire.read()); mday = bcdToDec(Wire.read()); month = bcdToDec(Wire.read()); year = bcdToDec(Wire.read()); } uint8_t decToBcd(uint8_t value) { return ((value / 10 * 16) + (value % 10)); } uint8_t bcdToDec(uint8_t value) { return ((value / 16 * 10) + (value % 16)); } // RTC Zeit void getTime(char *psz, bool f = true) { sprintf(psz, "%02d%c%02d", hours, (f ? ':' : ' '), minutes); } // RTC Datum void getDate(char *psz) { char szBuf[10]; sprintf(psz, "%d %s %04d", mday , mon2str(month, szBuf, sizeof(szBuf) - 1), (year + 2000)); } // Temperatur void getTemperature() { // Messzeit abwarten if ((millis() - timerDHT) > TIMEDHT) { timerDHT = millis(); // Luftfeuchte humidity = dht.readHumidity(); // Temperatur °C celsius = dht.readTemperature(); // Temperatur °F fahrenheit = dht.readTemperature(true); // Überprüfe DHT11 if (isnan(humidity) || isnan(celsius) || isnan(fahrenheit)) { Serial.println("DHT11 Sensor Fehler!"); return; } } } // Abrufen eines Labels von PROGMEM in ein char-Array char *mon2str(uint8_t mon, char *psz, uint8_t len) { static const __FlashStringHelper* str[] = { F("Jan"), F("Feb"), F("Mar"), F("Apr"), F("Mai"), F("Jun"), F("Jul"), F("Aug"), F("Sep"), F("Okt"), F("Nov"), F("Dez") }; strncpy_P(psz, (const char PROGMEM *)str[mon - 1], len); psz[len] = '\0'; return (psz); } char *dow2str(uint8_t code, char *psz, uint8_t len) { static const __FlashStringHelper* str[] = { F("Sonntag"), F("Montag"), F("Dienstag"), F("Mittwoch"), F("Donnerstag"), F("Freitag"), F("Samstag") }; strncpy_P(psz, (const char PROGMEM *)str[code - 1], len); psz[len] = '\0'; return (psz); } void setup(void) { Wire.begin(); P.begin(2); P.setInvert(false); P.setZone(0, MAX_DEVICES - 4, MAX_DEVICES - 1); P.setZone(1, MAX_DEVICES - 4, MAX_DEVICES - 1); P.displayZoneText(1, szTime, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT); P.displayZoneText(0, szMesg, PA_CENTER, SPEED_TIME, 0, PA_PRINT , PA_NO_EFFECT); P.addChar('$', degC); P.addChar('&', degF); dht.begin(); } void loop(void) { static uint32_t lastTime = 0; // Memory (ms) static uint8_t display = 0; // Current display mode static bool flasher = false; // Seconds passing flasher beginDS1307(); getTemperature(); P.displayAnimate(); if (P.getZoneStatus(0)) { switch (display) { case 0: // Temperatur °C P.setPause(0, 1000); P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_UP); display++; dtostrf(celsius, 3, 1, szMesg); strcat(szMesg, "$"); break; case 1: // Luftfeuchte P.setTextEffect(0, PA_SCROLL_DOWN, PA_SCROLL_LEFT); display++; dtostrf(humidity, 3, 0, szMesg); strcat(szMesg, "%LF "); break; case 2: // Uhrzeit P.setFont(0, numeric7Seg); P.setTextEffect(0, PA_PRINT, PA_NO_EFFECT); P.setPause(0, 0); if ((millis() - lastTime) >= 1000) { lastTime = millis(); getTime(szMesg, flasher); flasher = !flasher; } if ((seconds == 10) || (seconds == 20) || (seconds == 30)|| (seconds == 40)|| (seconds == 50)|| (seconds == 60)) { display++; P.setTextEffect(0, PA_PRINT, PA_WIPE_CURSOR); } break; delay(3000); case 3: // Wochentag P.setFont(0, nullptr); P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT); display++; dow2str(wday, szMesg, MAX_MESG); break; default: // Kalender P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT); display = 0; getDate(szMesg); break; } P.displayReset(0); } }