#include #include #include "LedMatrix.h" #include #include //RealTimeClock RTClib RTC; DS3231 Clock; //Display #define NUMBER_OF_DEVICES 4 #define CS_PIN 10 LedMatrix ledMatrix = LedMatrix(NUMBER_OF_DEVICES, CS_PIN); //ConfigData (Name and Pin-Numbers) const String NodeName = "Wecker"; //Pin Taster const int pinTime = 2; //Pin fuer Toggle_Power und Einstellen der Uhrzeit (Lang) const int pinSet = 3; //Pin fuer Sleep und Zeit_Einstellung im Alarm/Time Set Mode const int pinAlarm = 4; //Pin fuer Alarm An/Aus und setzen der Alarmzeiten (Lang) const int pinInput = 5; //Pin für die Eingangswahl const int pinSleep = 6; //Pin Unbenutzt //Pin Relay const int outInput = 7; const int outPower = 8; //For Summertime change notification (change alarmtime) this should be saved in the EEPROM! bool summer = false; //Alarm int al1h = 0; int al1m = 0; int al2h = 0; int al2m = 0; unsigned long time_on = -1; int minutes_sleep = -1; //Current Date and Time from RTC int h = 0; int m = 0; int s = 0; int d = 0; int M = 0; int y = 0; char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; String dow = "-"; int setItem = 0; long block_gui = -1; unsigned long previousMillis = 0; void setup() { Serial.begin(115200); delay(10); Wire.begin(); //Setup Display ledMatrix.init(); ledMatrix.setTextAlignment(0); ledMatrix.setRotation(true); ledMatrix.setIntensity(0); display_text("U"); delay(400); display_text("Uh"); delay(400); display_text("Uhr"); delay(400); display_text("Uhr"); delay(500); //restore data get_eeprom(); //Pin Setup pinMode(pinTime, INPUT_PULLUP); // set pin to input digitalWrite(pinTime, HIGH); // turn on pullup resistors pinMode(pinSet, INPUT_PULLUP); // set pin to input digitalWrite(pinSet, HIGH); // turn on pullup resistors pinMode(pinAlarm, INPUT_PULLUP); // set pin to input digitalWrite(pinAlarm, HIGH); // turn on pullup resistors pinMode(pinInput, INPUT_PULLUP); // set pin to input digitalWrite(pinInput, HIGH); // turn on pullup resistors pinMode(pinSleep, INPUT_PULLUP); // set pin to input digitalWrite(pinSleep, HIGH); // turn on pullup resistors pinMode(outPower, OUTPUT); // set pin to input digitalWrite(outPower, HIGH); // turn on pullup resistors pinMode(outInput, OUTPUT); // set pin to input digitalWrite(outInput, HIGH); // turn on pullup resistors delay(500); //Set Alarm Times DateTime now = RTC.now(); d = now.day(); M = now.month(); y = now.year(); h = now.hour(); //24-hr byte A1Day, A1Hour, A1Minute, A1Second, AlarmBits; bool A1Dy, A1h12, A1PM; Clock.getA1Time(A1Day, A1Hour, A1Minute, A1Second, AlarmBits, A1Dy, A1h12, A1PM); if (summer) { al1h = A1Hour + 1; } else{ al1h = A1Hour; } al1m = A1Minute; Serial.println("Alarm1 Set:" + String(A1Day) + ", " + String(A1Hour) + ", " + String(A1Minute) + ", " + String(AlarmBits) + ", " + String(A1Dy) + ", " + String(A1h12) + ", "); Clock.getA2Time(A1Day, A1Hour, A1Minute, AlarmBits, A1Dy, A1h12, A1PM); if (summer) { al2h = A1Hour + 1; } else{ al2h = A1Hour; } al2m = A1Minute; Serial.println("Alarm2 Set:" + String(A1Day) + ", " + String(A1Hour) + ", " + String(A1Minute) + ", " + String(AlarmBits) + ", " + String(A1Dy) + ", " + String(A1h12) + ", "); delay(1000); previousMillis = millis(); } void loop() { unsigned long currentMillis = millis(); unsigned long intervall = currentMillis - previousMillis; release_gui(currentMillis); // put your main code here, to run repeatedly: if(setItem == 0){ update_Time(); run_alarm(); if (block_gui < 0) show_current_time(intervall,currentMillis); } else{ show_time_infos(intervall,currentMillis); previousMillis = currentMillis; } test_pin(); handleSleep(intervall, currentMillis); delay(80); }