arduino:schlafphasenwecker:programmversion_0.4
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
arduino:schlafphasenwecker:programmversion_0.4 [19.12.2016 11:56] – Frickelpiet | arduino:schlafphasenwecker:programmversion_0.4 [18.05.2023 12:34] (aktuell) – Externe Bearbeitung 127.0.0.1 | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
====== Schlafphasenwecker Programmversion 0.4 ====== | ====== Schlafphasenwecker Programmversion 0.4 ====== | ||
- | Es kann nun ein Weckalarm | + | <box 30% green right|**Achtung**> |
- | Tags: #Arduino # | + | Die gesamte Menüstruktur wurde aufgehübscht. Das neue Design zitiert Grundformen des Schlafphasenweckers. |
+ | |||
+ | Der Wecker ist nun außerdem in der Lage, die Sonnenauf- und -untergangszeiten zu berechnen. | ||
+ | |||
+ | Hilfreiche Links: | ||
+ | * https:// | ||
+ | * Übersicht über die Funktionen der Time-Library: | ||
+ | * Berechnung von Sonnenauf- und untergang: https:// | ||
+ | * Aufteilen von Projekten auf mehrere Dateien: http:// | ||
+ | * http:// | ||
+ | |||
+ | ToDos: | ||
+ | * Der Sketch würde übersichtlicher, | ||
+ | |||
+ | < | ||
+ | // Schlafphasenwecker Version 0.4 | ||
+ | |||
+ | // Bibliotheken einbinden | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | //#include " | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | //#include < | ||
+ | |||
+ | |||
+ | // Definiert Adressen im EEPROM | ||
+ | int addrAlarmHour = 0; | ||
+ | int addrAlarmMinute = 1; | ||
+ | int addrAlarmMode = 2; | ||
+ | |||
+ | |||
+ | // Definiert die Pins | ||
+ | #define DCF_PIN 2 // Connection pin to DCF 77 device | ||
+ | #define DCF_INTERRUPT 2 // Interrupt number associated with pin | ||
+ | #define TFTbacklightPin 7 // PWM Backlight TFT | ||
+ | |||
+ | // Definiert die Farben für das Menü (im RGB585-Format) | ||
+ | #define white 0xFFFF | ||
+ | #define black 0x0000 | ||
+ | #define red 0xF800 | ||
+ | #define orange | ||
+ | |||
+ | // Definiert die DCF77-Bibliothek | ||
+ | DCF77 DCF = DCF77(DCF_PIN, | ||
+ | |||
+ | // The FT6206 uses hardware I2C (SCL/SDA) | ||
+ | Adafruit_FT6206 ctp = Adafruit_FT6206(); | ||
+ | |||
+ | // The display also uses hardware SPI, plus #9 & #10 | ||
+ | #define TFT_CS 10 // ChipSelect-Signal an Teensy-Pin 10 | ||
+ | #define TFT_DC 9 // Data/ | ||
+ | Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, | ||
+ | |||
+ | // pass in a number for the sensor identifier (for your use later) | ||
+ | Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); | ||
+ | |||
+ | /* Assign a unique ID to this sensor at the same time */ | ||
+ | Adafruit_LSM303_Accel_Unified accel(30301); | ||
+ | Adafruit_LSM303_Mag_Unified | ||
+ | |||
+ | // Create simple AHRS algorithm using the above sensors. | ||
+ | Adafruit_Simple_AHRS | ||
+ | |||
+ | // Definiert die Variablen | ||
+ | //int sensorValue; | ||
+ | int flankUp = 0; | ||
+ | int flankDown = 0; | ||
+ | int PreviousflankUp; | ||
+ | bool Up = false; | ||
+ | |||
+ | boolean IMUconnected = false; | ||
+ | boolean DCFtimesignalFound = false; | ||
+ | |||
+ | time_t DCFtime = 0; // Das aktuelleste erfolgreich empfangene Zeitzeichen im Variablenformat time_t (Sekunden seit dem 1.1.1970) | ||
+ | time_t t = 0; // Die Zeit der Real Time Clock im Variablenformat time_t (Sekunden seit dem 1.1.1970) | ||
+ | time_t DefaultTime = 1477958400; | ||
+ | unsigned long lastDCFsignal; | ||
+ | unsigned long noDCFsignal; | ||
+ | unsigned long currentDCFsignal; | ||
+ | unsigned long receivedDCFsignals = 0; // Zählt die Anzahl der erfolgreich empfangenen DCF77-Zeitzeichen seit dem Systemstart. | ||
+ | float DCFsuccessRate = 0; // Wert für die Quote der erfolgreich empfangenen DCF77-Zeitzeichen seit dem Systemstart. | ||
+ | |||
+ | int alarmHour = 6; // Stunde, zu der ein Alarm ausgelöst werden soll. Wird als Integer definiert, damit die Variable theoretisch negativ werden kann. (Das ist für den Rollover von 0 auf 23 nötig.) | ||
+ | int alarmMinute = 0; // Minute, zu der ein Alarm ausgelöst werden soll. Wird als Integer definiert, damit die Variable theoretisch negativ werden kann. (Das ist für den Rollover von 0 auf 45 nötig.) | ||
+ | byte alarmMode = 0; // Alarmmodus (0 = Alarm aus) | ||
+ | boolean alarmOn = false; | ||
+ | |||
+ | uint16_t ir; // Helligkeitswert für den Infrarotanteil des Lichts | ||
+ | uint16_t full; // Helligkeitswert für das Infrarotanteil und das sichtbare Licht | ||
+ | uint32_t lum; | ||
+ | uint16_t lux; | ||
+ | |||
+ | boolean touch = false; | ||
+ | boolean prevtouch = false; | ||
+ | boolean touch2 = false; | ||
+ | boolean prevtouch2 = false; | ||
+ | |||
+ | boolean TFTbacklightOn = false; | ||
+ | byte TFTbrightness = 0; // Wert für die aktuelle Helligkeit des TFT Backlights | ||
+ | //byte TFTmaxbrightness = 255; // Wert für die maximale Helligkeit des TFT backlights | ||
+ | //byte TFTminbrightness = 0; // Wert für die minimale Helligkeit des TFT backlights | ||
+ | const unsigned long TFTbacklightDelay = 60000; // Zeit in Millisekunden, | ||
+ | unsigned long TFTbacklightTime = 0; | ||
+ | |||
+ | |||
+ | //boolean touchtouched2 = false; | ||
+ | boolean TFTrefresh = false; | ||
+ | |||
+ | //int i; // Zählwert für Fadein und Fadeout des TFT Backlights | ||
+ | |||
+ | byte menuPage = 0; // Wert für das aktuell auf dem TFT angezeigten Menü. Gestartet wird mit Menü Nr. 0. | ||
+ | byte previousmenuPage = 1; // Wert für die Menüseite, die in dem vormaligen Durchlauf aktuell war. | ||
+ | //boolean touchtouched = false; | ||
+ | int tx; // Auf dem Touchscreen gedrücktes Pixel auf der x-Achse. Pixelspalte Nr. 0 ist links. | ||
+ | int ty; // Auf dem Touchscreen gedrücktes Pixel auf der y-Achse. Pixelzeile Nr. 0 ist oben. | ||
+ | //const unsigned long debouncetime = 5; // Zeit für " | ||
+ | //unsigned long touchtime = 0; // Speichert die Zeit, zu der der Touchscreen berührt wird. | ||
+ | |||
+ | |||
+ | float accelX; | ||
+ | float accelY; | ||
+ | float accelZ; | ||
+ | |||
+ | float roll; | ||
+ | float pitch; | ||
+ | float heading; | ||
+ | |||
+ | |||
+ | // Definiert die Tracking-Variablen für die IF-Abfragen | ||
+ | unsigned long previousMillisSetRTC = 0; | ||
+ | unsigned long previousMillisAlarmClock = 0; | ||
+ | unsigned long previousMillisTFTScreen = 0; | ||
+ | unsigned long previousMillisTouchScreen = 0; | ||
+ | unsigned long previousMillisSensorData = 0; | ||
+ | unsigned long previousMillisSerialPrint = 0; | ||
+ | unsigned long previousMillisDCFPulseLength = 0; | ||
+ | |||
+ | // Definiert die Intervalle für die IF-Abfragen in Millisekunden | ||
+ | const unsigned long intervalSetRTC = 1000; // konstanter Delay für Holen der Zeit | ||
+ | const unsigned long intervalAlarmClock = 1000; // konstanter Delay für die Weckfunktionen | ||
+ | unsigned long intervalTFTScreen = 100; // variabler Delay für Anteuerung des TFT-Screens | ||
+ | const unsigned long intervalTouchScreen = 50; // konstanter Delay für Anteuerung des kapazitiven Touchsreens | ||
+ | const unsigned long intervalSensorData = 500; // konstanter Delay für Auslesen der Sensoren | ||
+ | const unsigned long intervalSerialPrint = 1000; // konstanter Delay für serielle Ausgabe | ||
+ | const unsigned long intervalDCFPulseLength = 1; // konstanter Delay für die Messung der Periode und Pulsweite des Zeitsignals | ||
+ | |||
+ | |||
+ | void setup() | ||
+ | // Initalisiert die Pins | ||
+ | pinMode(DCF_PIN, | ||
+ | pinMode(TFTbacklightPin, | ||
+ | |||
+ | // set the Time library to use Teensy 3.0's RTC to keep time | ||
+ | setSyncProvider(getTeensy3Time); | ||
+ | |||
+ | // Initialisiert den TFT-Bildschirm | ||
+ | tft.begin(); | ||
+ | tft.setRotation(1); | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | |||
+ | // Initialisiert die serielle Schnittstelle | ||
+ | Serial.begin(115200); | ||
+ | |||
+ | // Zeigt auf dem TFT einen Startbildschirm an | ||
+ | // | ||
+ | |||
+ | delay(100); | ||
+ | if (timeStatus()!= timeSet) { | ||
+ | Serial.println(" | ||
+ | } else { | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | if (! ctp.begin(40)) { // Stellt u.a. die Sensitivität des Touchscreens ein | ||
+ | Serial.println(" | ||
+ | //while (1); | ||
+ | } else { | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | /* Initiolisiere den Beschleunigungssensor LSM303 */ | ||
+ | if(!accel.begin()) { | ||
+ | /* There was a problem detecting the ADXL345 ... check your connections */ | ||
+ | Serial.println(" | ||
+ | // | ||
+ | } else { | ||
+ | IMUconnected = true; | ||
+ | } | ||
+ | if(!mag.begin()) { | ||
+ | /* There was a problem detecting the ADXL345 ... check your connections */ | ||
+ | Serial.println(" | ||
+ | // | ||
+ | } | ||
+ | |||
+ | |||
+ | // Konfiguration des TSL2591 | ||
+ | // You can change the gain on the fly, to adapt to brighter/ | ||
+ | // | ||
+ | tsl.setGain(TSL2591_GAIN_MED); | ||
+ | // tsl.setGain(TSL2591_GAIN_HIGH); | ||
+ | |||
+ | // Changing the integration time gives you a longer time over which to sense light | ||
+ | // longer timelines are slower, but are good in very low light situtations! | ||
+ | tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS); | ||
+ | // tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS); | ||
+ | // tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS); | ||
+ | // tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS); | ||
+ | // | ||
+ | // tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS); | ||
+ | |||
+ | // Initialisiert den TSL2591 | ||
+ | tsl.begin(); | ||
+ | |||
+ | // Displays some basic information on this sensor from the unified sensor API sensor_t type | ||
+ | sensor_t sensor; | ||
+ | tsl.getSensor(& | ||
+ | Serial.println(" | ||
+ | Serial.print | ||
+ | Serial.print | ||
+ | Serial.print | ||
+ | Serial.print | ||
+ | Serial.print | ||
+ | Serial.print | ||
+ | Serial.println(" | ||
+ | Serial.println("" | ||
+ | |||
+ | |||
+ | // Startet die Abfrage des DCF77-Moduls | ||
+ | DCF.Start(); | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | |||
+ | |||
+ | // Lese die abgespeicherten Werte für die Alarmzeit und -modus | ||
+ | alarmHour = EEPROM.read(addrAlarmHour); | ||
+ | alarmMinute = EEPROM.read(addrAlarmMinute); | ||
+ | alarmMode = EEPROM.read(addrAlarmMode); | ||
+ | |||
+ | // Es wird einmalig die Funktion zur Berechnung des Sonnenauf- und untergangs aufgerufen. | ||
+ | sunrise(); | ||
+ | } | ||
+ | |||
+ | |||
+ | void loop() { | ||
+ | // Aktuelle Zeit abfragen | ||
+ | unsigned long currentMillis = millis(); | ||
+ | |||
+ | |||
+ | // Stelle die Real Time Clock (RTC) auf die aktuelle Zeit | ||
+ | if ((unsigned long)(currentMillis - previousMillisSetRTC) >= intervalSetRTC) { | ||
+ | |||
+ | DCFtime = DCF.getTime(); | ||
+ | |||
+ | // Wenn die serielle Schnittstelle verfügbar ist, setze die RTC auf diese Zeit | ||
+ | if (Serial.available() && DCFtime < DefaultTime) { | ||
+ | t = processSyncMessage(); | ||
+ | if (t != 0) { | ||
+ | Teensy3Clock.set(t); | ||
+ | setTime(t); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Wenn ein Zeitsignal vom DCF77-Modul verfügbar ist, setze die RTC auf diese Zeit | ||
+ | if (DCFtime > DefaultTime) { | ||
+ | t = DCFtime; | ||
+ | Serial.println(" | ||
+ | Teensy3Clock.set(t); | ||
+ | setTime(t); | ||
+ | DCFtimesignalFound = true; | ||
+ | receivedDCFsignals = receivedDCFsignals + 1; | ||
+ | currentDCFsignal = millis(); | ||
+ | } | ||
+ | |||
+ | // Berechne die Zeit (in Sekunden) die seit dem Empfang des letzten gültigen DCF-Signals vergangen ist | ||
+ | if (DCFtimesignalFound == false) { | ||
+ | noDCFsignal = millis() /1000; | ||
+ | } | ||
+ | else { | ||
+ | lastDCFsignal = (millis() - currentDCFsignal) / 1000; | ||
+ | } | ||
+ | |||
+ | |||
+ | // Berechnet die Quote erfolgreich empfangener DCF77-Signale seit dem letzten Systemstart | ||
+ | DCFsuccessRate = (receivedDCFsignals / ((millis() / 60000))) * 100; | ||
+ | |||
+ | //Speichere die aktuelle Zeit in die zughörige Variable | ||
+ | previousMillisSetRTC = currentMillis; | ||
+ | } | ||
+ | |||
+ | |||
+ | // Alarm-Funktionen | ||
+ | if ((unsigned long)(currentMillis - previousMillisAlarmClock) >= intervalAlarmClock) { | ||
+ | if (alarmMode != 0 && hour() == alarmHour && minute() == alarmMinute && second() == 0 || alarmOn == true) { | ||
+ | |||
+ | if (alarmMode == 1) { | ||
+ | Serial.print(" | ||
+ | } | ||
+ | else if (alarmMode == 2) { | ||
+ | Serial.print(" | ||
+ | } | ||
+ | else if (alarmMode == 3) { | ||
+ | Serial.print(" | ||
+ | } | ||
+ | |||
+ | TFTbrightness = 255; | ||
+ | analogWrite(TFTbacklightPin, | ||
+ | TFTbacklightOn = true; | ||
+ | alarmOn = true; | ||
+ | |||
+ | if (menuPage != 7) { // Das Menü "Alarm aus/ | ||
+ | menuPage = 7; | ||
+ | TFTrefresh = true; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | //Speichere die aktuelle Zeit in die zughörige Variable | ||
+ | previousMillisAlarmClock = currentMillis; | ||
+ | } | ||
+ | |||
+ | |||
+ | // Abfrage verschiedener Sensoren | ||
+ | if ((unsigned long)(currentMillis - previousMillisSensorData) >= intervalSensorData) { | ||
+ | |||
+ | if (IMUconnected == true) { | ||
+ | // Auslesen des Beschleunigungs- / Lagesensors und Magnetometers LSM303 | ||
+ | sensors_event_t event; | ||
+ | accel.getEvent(& | ||
+ | sensors_vec_t | ||
+ | ahrs.getOrientation(& | ||
+ | |||
+ | accelX = event.acceleration.x; | ||
+ | accelY = event.acceleration.y; | ||
+ | accelZ = event.acceleration.z; | ||
+ | |||
+ | roll = orientation.roll; | ||
+ | pitch = orientation.pitch; | ||
+ | heading = orientation.heading; | ||
+ | } | ||
+ | |||
+ | |||
+ | //Auslesen des Helligkeitssensors TSL2591 | ||
+ | lum = tsl.getFullLuminosity(); | ||
+ | ir = lum >> 16; | ||
+ | full = lum & 0xFFFF; | ||
+ | lux = tsl.calculateLux(full, | ||
+ | |||
+ | //Speichere die aktuelle Zeit in die zughörige Variable | ||
+ | previousMillisSensorData = currentMillis; | ||
+ | } | ||
+ | |||
+ | |||
+ | // TFT- imd Touchscreen | ||
+ | if ((unsigned long)(currentMillis - previousMillisTouchScreen) >= intervalTouchScreen) { | ||
+ | |||
+ | // Auslesen des kapazitiven Touchsensors | ||
+ | if (ctp.touched()) { | ||
+ | // Retrieve a point | ||
+ | TS_Point p = ctp.getPoint(); | ||
+ | // Damit der Wert 0, 0 des Touchsensors mit dem Pixel 0, 0 des TFT-Screens übereinstimmt, | ||
+ | tx = map(p.y, 0, 320, 320, 0); | ||
+ | ty = p.x; | ||
+ | |||
+ | // Variablen für die Steuerung des Backlights | ||
+ | touch = true; // Wird wahr, so lange der Touchsensor berührt wird (d.h. wird am Ende der TouchScreen-Schleife false). | ||
+ | prevtouch = touch; | ||
+ | TFTbacklightTime = currentMillis; | ||
+ | |||
+ | // Variablen für die Steurung des Menüs | ||
+ | if (TFTbacklightOn == true) { | ||
+ | touch2 = true; | ||
+ | prevtouch2 = touch2; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Das Backlight wird eingeschaltet, | ||
+ | if (touch == false && prevtouch == true) { | ||
+ | TFTbrightness = 255; | ||
+ | analogWrite(TFTbacklightPin, | ||
+ | TFTbacklightOn = true; | ||
+ | TFTrefresh = true; // Wenn das Backlight eingeschaltet wird, muss einmal das alte Menü aufgebaut werden | ||
+ | prevtouch = false; | ||
+ | } | ||
+ | |||
+ | // Wenn das Backlight an ist, soll es nach einer bestimmten Zeit wieder ausgeschaltet werden. Allerdings nur dann, wenn keine Alarmfunktion läuft. | ||
+ | if (alarmOn == false) { | ||
+ | if (TFTbacklightOn == true && (millis() > TFTbacklightTime + TFTbacklightDelay)) { | ||
+ | TFTbrightness = TFTbrightness - 1; | ||
+ | if (TFTbrightness == 0) { | ||
+ | TFTbacklightOn = false; | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | } | ||
+ | analogWrite(TFTbacklightPin, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Wenn das Backlight an ist, kann das Menü mit dem Touchsensor bedient werden | ||
+ | // Es folgen für jedes einzelne Menü die Definitionen der jeweils sensiblen Bereiche einschließlich der Befehle, die jeweils ausgelöst werden sollen. | ||
+ | if (menuPage == 0 && touch2 == false && prevtouch2 == true) { // Wenn der Touchscreen losgelassen wurd und Menüseite 0 ausgewählt ist ... | ||
+ | if ((tx >= 0) && (tx <= 120) && (ty >= 0) && (ty <= 59)) { // ... und der TouchScreen in dem angegebenen Bereich berührt wird ... | ||
+ | menuPage = 1; // ... dann rufe Menüseite 1 auf. | ||
+ | } | ||
+ | else if ((tx >= 0) && (tx <= 120) && (ty >= 60) && (ty <= 120)) { | ||
+ | menuPage = 2; | ||
+ | } | ||
+ | else if ((tx >= 0) && (tx <= 120) && (ty >= 121) && (ty <= 180)) { | ||
+ | menuPage = 3; | ||
+ | } | ||
+ | else if ((tx >= 0) && (tx <= 120) && (ty >= 181) && (ty <= 240)) { | ||
+ | menuPage = 4; | ||
+ | } | ||
+ | else if ((tx >= 121) && (tx <= 320) && (ty >= 1) && (ty <= 240)) { | ||
+ | menuPage = 5; | ||
+ | } | ||
+ | TFTrefresh = true; // Aktualisiere den Inhalt des TFT-Screens | ||
+ | prevtouch2 = false; | ||
+ | } | ||
+ | |||
+ | // Menü Snoozle | ||
+ | if (menuPage == 1 && touch2 == false && prevtouch2 == true) { | ||
+ | // Zurück zum Hauptmenü | ||
+ | if ((tx >= 0) && (tx <= 40) && (ty >= 0) && (ty <= 240)) { | ||
+ | menuPage = 0; | ||
+ | } | ||
+ | else if ((tx >= 41) && (tx <= 320) && (ty >= 0) && (ty <= 240)) { | ||
+ | menuPage = 0; | ||
+ | } | ||
+ | TFTrefresh = true; | ||
+ | prevtouch2 = false; | ||
+ | } | ||
+ | |||
+ | // Menü Ziffernblatt | ||
+ | if (menuPage == 2 && touch2 == false && prevtouch2 == true) { | ||
+ | // Zurück zum Hauptmenü | ||
+ | if ((tx >= 0) && (tx <= 40) && (ty >= 0) && (ty <= 240)) { | ||
+ | menuPage = 0; | ||
+ | } | ||
+ | else if ((tx >= 41) && (tx <= 320) && (ty >= 0) && (ty <= 240)) { | ||
+ | menuPage = 0; | ||
+ | } | ||
+ | TFTrefresh = true; | ||
+ | prevtouch2 = false; | ||
+ | } | ||
+ | |||
+ | // Menü Einstellungen | ||
+ | if (menuPage == 3 && touch2 == false && prevtouch2 == true) { | ||
+ | // Zurück zum Hauptmenü | ||
+ | if ((tx >= 0) && (tx <= 40) && (ty >= 0) && (ty <= 240)) { | ||
+ | menuPage = 0; | ||
+ | } | ||
+ | else if ((tx >= 41) && (tx <= 320) && (ty >= 0) && (ty <= 240)) { | ||
+ | menuPage = 0; | ||
+ | } | ||
+ | TFTrefresh = true; | ||
+ | prevtouch2 = false; | ||
+ | } | ||
+ | |||
+ | // Menü Informationen | ||
+ | if (menuPage == 4 && touch2 == false && prevtouch2 == true) { | ||
+ | // Zurück zum Hauptmenü | ||
+ | if ((tx >= 0) && (tx <= 40) && (ty >= 0) && (ty <= 240)) { | ||
+ | menuPage = 0; | ||
+ | } | ||
+ | // Zum Uhntermenü DCF Zeitsignal | ||
+ | else if ((tx >= 51) && (tx <= 184) && (ty >= 0) && (ty <= 59)) { // ... und der TouchScreen in dem angegebenen Bereich berührt wird ... | ||
+ | menuPage = 41; // ... dann rufe Menüseite 1 auf. | ||
+ | } | ||
+ | // Zum Untermenü LSM303 | ||
+ | else if ((tx >= 51) && (tx <= 184) && (ty >= 60) && (ty <= 120)) { | ||
+ | menuPage = 42; | ||
+ | } | ||
+ | /* | ||
+ | // Zum Menü " | ||
+ | else if ((tx >= 51) && (tx <= 184) && (ty >= 121) && (ty <= 180)) { | ||
+ | menuPage = 43; | ||
+ | } | ||
+ | // Zum Menü " | ||
+ | else if ((tx >= 51) && (tx <= 184) && (ty >= 181) && (ty <= 240)) { | ||
+ | menuPage = 44; | ||
+ | } | ||
+ | */ | ||
+ | // Zum Menü TSL2591-Sensor | ||
+ | else if ((tx >= 186) && (tx <= 319) && (ty >= 0) && (ty <= 59)) { // ... und der TouchScreen in dem angegebenen Bereich berührt wird ... | ||
+ | menuPage = 45; // ... dann rufe Menüseite 1 auf. | ||
+ | } | ||
+ | /* | ||
+ | // Zum Menü " | ||
+ | else if ((tx >= 186) && (tx <= 319) && (ty >= 60) && (ty <= 120)) { | ||
+ | menuPage = 46; | ||
+ | } | ||
+ | // Zum Menü " | ||
+ | else if ((tx >= 186) && (tx <= 319) && (ty >= 121) && (ty <= 180)) { | ||
+ | menuPage = 47; | ||
+ | } | ||
+ | // Zum Menü " | ||
+ | else if ((tx >= 186) && (tx <= 319) && (ty >= 181) && (ty <= 240)) { | ||
+ | menuPage = 48; | ||
+ | } | ||
+ | */ | ||
+ | TFTrefresh = true; | ||
+ | prevtouch2 = false; | ||
+ | } | ||
+ | |||
+ | // Untermenü DCF77 Zeitsignal | ||
+ | if (menuPage == 41 && touch2 == false && prevtouch2 == true) { | ||
+ | // Zurück zum Untermenü Informationen | ||
+ | if ((tx >= 0) && (tx <= 40) && (ty >= 0) && (ty <= 240)) { | ||
+ | menuPage = 4; | ||
+ | } | ||
+ | else if ((tx >= 41) && (tx <= 320) && (ty >= 0) && (ty <= 240)) { | ||
+ | menuPage = 4; | ||
+ | } | ||
+ | TFTrefresh = true; | ||
+ | prevtouch2 = false; | ||
+ | } | ||
+ | |||
+ | // Untermenü TSL2591 Sensor | ||
+ | if (menuPage == 45 && touch2 == false && prevtouch2 == true) { | ||
+ | // Zurück zum Untermenü Informationen | ||
+ | if ((tx >= 0) && (tx <= 40) && (ty >= 0) && (ty <= 240)) { | ||
+ | menuPage = 4; | ||
+ | } | ||
+ | else if ((tx >= 41) && (tx <= 320) && (ty >= 0) && (ty <= 240)) { | ||
+ | menuPage = 4; | ||
+ | } | ||
+ | TFTrefresh = true; | ||
+ | prevtouch2 = false; | ||
+ | } | ||
+ | |||
+ | // Untermenü TSL303 Sensor | ||
+ | if (menuPage == 42 && touch2 == false && prevtouch2 == true) { | ||
+ | // Zurück zum Untermenü Informationen | ||
+ | if ((tx >= 0) && (tx <= 40) && (ty >= 0) && (ty <= 240)) { | ||
+ | menuPage = 4; | ||
+ | } | ||
+ | else if ((tx >= 41) && (tx <= 320) && (ty >= 0) && (ty <= 240)) { | ||
+ | menuPage = 4; | ||
+ | } | ||
+ | TFTrefresh = true; | ||
+ | prevtouch2 = false; | ||
+ | } | ||
+ | |||
+ | // Menü Alarmzeit stellen | ||
+ | if (menuPage == 5 && touch2 == false && prevtouch2 == true) { | ||
+ | // Zurück zum Hauptmenü | ||
+ | if ((tx >= 0) && (tx <= 49) && (ty >= 0) && (ty <= 239)) { | ||
+ | menuPage = 0; | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | // Um das EEPROM zu schonen, werden die Alarmzeit und der Alarmmodus erst gespeichert, | ||
+ | // Um Speicherplatz im EEPROM zu sparen, werden die Integervariablen alarmHour und alarmMinute als Byte gespeichert. | ||
+ | EEPROM.write(addrAlarmHour, | ||
+ | EEPROM.write(addrAlarmMinute, | ||
+ | EEPROM.write(addrAlarmMode, | ||
+ | } | ||
+ | // Stunden auf | ||
+ | else if ((tx >= 50) && (tx <= 159) && (ty >= 0) && (ty <= 119)) { | ||
+ | alarmHour = alarmHour + 1; | ||
+ | if (alarmHour >= 24) { | ||
+ | alarmHour = 0; | ||
+ | } | ||
+ | } | ||
+ | // Minuten auf | ||
+ | else if ((tx >= 160) && (tx <= 268) && (ty >= 0) && (ty <= 119)) { | ||
+ | alarmMinute = alarmMinute + 5; | ||
+ | if (alarmMinute >= 60) { | ||
+ | alarmMinute = 0; | ||
+ | } | ||
+ | } | ||
+ | // Stunden ab | ||
+ | else if ((tx >= 50) && (tx <= 159) && (ty >= 120) && (ty <= 239)) { | ||
+ | alarmHour = alarmHour - 1; | ||
+ | if (alarmHour < 0) { | ||
+ | alarmHour = 23; | ||
+ | } | ||
+ | } | ||
+ | // Minuten ab | ||
+ | else if ((tx >= 160) && (tx <= 268) && (ty >= 120) && (ty <= 239)) { | ||
+ | alarmMinute = alarmMinute - 5; | ||
+ | if (alarmMinute < 0) { | ||
+ | alarmMinute = 45; | ||
+ | } | ||
+ | } | ||
+ | // Zum Menü Weckmodus stellen | ||
+ | else if ((tx >= 269) && (tx <= 319) && (ty >= 0) && (ty <= 239)) { | ||
+ | menuPage = 51; | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | } | ||
+ | TFTrefresh = true; | ||
+ | prevtouch2 = false; | ||
+ | } | ||
+ | |||
+ | // Untermenü Weckmodus stellen | ||
+ | if (menuPage == 51 && touch2 == false && prevtouch2 == true) { | ||
+ | // Zurück zum Untermenü Informationen | ||
+ | if ((tx >= 0) && (tx <= 49) && (ty >= 0) && (ty <= 240)) { | ||
+ | menuPage = 5; | ||
+ | } | ||
+ | else if ((tx >= 50) && (tx <= 320) && (ty >= 0) && (ty <= 59)) { | ||
+ | alarmMode = 0; | ||
+ | } | ||
+ | else if ((tx >= 50) && (tx <= 320) && (ty >= 60) && (ty <= 119)) { | ||
+ | alarmMode = 1; | ||
+ | } | ||
+ | else if ((tx >= 50) && (tx <= 320) && (ty >= 120) && (ty <= 179)) { | ||
+ | alarmMode = 2; | ||
+ | } | ||
+ | else if ((tx >= 50) && (tx <= 320) && (ty >= 180) && (ty <= 239)) { | ||
+ | alarmMode = 3; | ||
+ | } | ||
+ | TFTrefresh = true; | ||
+ | prevtouch2 = false; | ||
+ | } | ||
+ | |||
+ | // Untermenü " | ||
+ | if (menuPage == 7 && touch2 == false && prevtouch2 == true) { | ||
+ | // Zurück zum Untermenü Informationen | ||
+ | if ((tx >= 0) && (tx <= 213) && (ty >= 0) && (ty <= 239)) { | ||
+ | menuPage = 0; | ||
+ | alarmOn = false; | ||
+ | } | ||
+ | else if ((tx >= 214) && (tx <= 319) && (ty >= 0) && (ty <= 239)) { | ||
+ | menuPage = 0; | ||
+ | alarmOn = false; | ||
+ | } | ||
+ | TFTrefresh = true; | ||
+ | prevtouch2 = false; | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | // Der Inhalt des Bildschirms wird nur dann neu aufgebaut, wenn a) das Backlight an ist und b) ein Refresh angewiesen wurde. | ||
+ | if (TFTbacklightOn == true) { | ||
+ | // Die Nummerierung der Menüseiten erfolgt nach dem folgendendem Muster: | ||
+ | // Hauptmenü = 0; von dort Verzweigungen zu den Untermenüs 1 bis 5 | ||
+ | |||
+ | // Hauptmenü | ||
+ | if (menuPage == 0 && TFTrefresh == true) { | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | |||
+ | // Linke Spalte des Menüs | ||
+ | tft.fillCircle(20, | ||
+ | tft.fillCircle(20, | ||
+ | tft.fillCircle(20, | ||
+ | tft.fillCircle(20, | ||
+ | |||
+ | tft.setTextColor(white); | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(15, | ||
+ | tft.print(" | ||
+ | tft.setCursor(15, | ||
+ | tft.print(" | ||
+ | tft.setCursor(15, | ||
+ | tft.print(" | ||
+ | tft.setCursor(15, | ||
+ | tft.print(" | ||
+ | |||
+ | // Anzeige Uhrzeit | ||
+ | tft.setTextColor(white, | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(190, | ||
+ | tft.print(" | ||
+ | if (DCFtimesignalFound == true) { | ||
+ | tft.setTextColor(red, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(white, | ||
+ | } | ||
+ | |||
+ | // Die Uhrzeit wird unabhängig davon einmal pro Sekunde aktualisiert | ||
+ | |||
+ | tft.fillRect(130, | ||
+ | |||
+ | //Anzeige Alarmzeit | ||
+ | tft.setTextColor(white, | ||
+ | if (alarmMode == 0) { | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(140, | ||
+ | tft.print(" | ||
+ | } | ||
+ | else { | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(180, | ||
+ | tft.print(" | ||
+ | |||
+ | tft.setFont(& | ||
+ | tft.setCursor(165, | ||
+ | if(alarmHour < 10) { | ||
+ | tft.print(' | ||
+ | } | ||
+ | tft.print(alarmHour); | ||
+ | tft.print(" | ||
+ | if(alarmMinute < 10) { | ||
+ | tft.print(' | ||
+ | } | ||
+ | tft.print(alarmMinute); | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(155, | ||
+ | tft.print(" | ||
+ | tft.print(alarmMode); | ||
+ | } | ||
+ | TFTrefresh = false; | ||
+ | } | ||
+ | |||
+ | if (menuPage == 0 && ((unsigned long)(currentMillis - previousMillisTFTScreen) >= intervalTFTScreen)) { | ||
+ | intervalTFTScreen = 1000; | ||
+ | |||
+ | tft.fillRect(140, | ||
+ | tft.setTextColor(white, | ||
+ | tft.setCursor(150, | ||
+ | tft.setFont(& | ||
+ | if(hour() < 10) { | ||
+ | tft.print(' | ||
+ | } | ||
+ | tft.print(hour()); | ||
+ | tftprintDigits(minute()); | ||
+ | tftprintDigits(second()); | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(170, | ||
+ | tft.print(day()); | ||
+ | tft.print(" | ||
+ | tft.print(month()); | ||
+ | tft.print(" | ||
+ | tft.print(year()); | ||
+ | |||
+ | previousMillisTFTScreen = currentMillis; | ||
+ | } | ||
+ | |||
+ | // Untermenü " | ||
+ | if (menuPage == 1 && TFTrefresh == true) { | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | |||
+ | // Zurück zum Hauptmenü | ||
+ | tft.fillCircle(20, | ||
+ | |||
+ | // Snoozle stellen | ||
+ | tft.setTextColor(white, | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(50, | ||
+ | tft.print(" | ||
+ | |||
+ | TFTrefresh = false; | ||
+ | } | ||
+ | |||
+ | // Untermenü " | ||
+ | if (menuPage == 2 && TFTrefresh == true) { | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | |||
+ | // Zurück zum Hauptmenü | ||
+ | tft.fillCircle(20, | ||
+ | |||
+ | // Effekte einstellen | ||
+ | tft.setTextColor(white, | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(50, | ||
+ | tft.print(" | ||
+ | |||
+ | TFTrefresh = false; | ||
+ | } | ||
+ | |||
+ | // Untermenü " | ||
+ | if (menuPage == 3 && TFTrefresh == true) { | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | |||
+ | // Zurück zum Hauptmenü | ||
+ | tft.fillCircle(20, | ||
+ | |||
+ | // Einstellungen stellen | ||
+ | tft.setTextColor(white, | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(50, | ||
+ | tft.print(" | ||
+ | |||
+ | TFTrefresh = false; | ||
+ | } | ||
+ | |||
+ | // Untermenü " | ||
+ | if (menuPage == 4 && TFTrefresh == true) { | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | |||
+ | // Zurück zum Hauptmenü | ||
+ | tft.fillCircle(20, | ||
+ | |||
+ | // Linke Spalte | ||
+ | tft.fillCircle(69, | ||
+ | tft.fillCircle(69, | ||
+ | tft.fillCircle(69, | ||
+ | tft.fillCircle(69, | ||
+ | |||
+ | tft.setTextColor(white); | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(64, | ||
+ | tft.print(" | ||
+ | tft.setCursor(64, | ||
+ | tft.print(" | ||
+ | tft.setCursor(64, | ||
+ | tft.print(" | ||
+ | tft.setCursor(64, | ||
+ | tft.print(" | ||
+ | |||
+ | // Rechte Spalte | ||
+ | tft.fillCircle(199, | ||
+ | tft.fillCircle(199, | ||
+ | tft.fillCircle(199, | ||
+ | tft.fillCircle(199, | ||
+ | |||
+ | tft.setTextColor(white); | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(194, | ||
+ | tft.print(" | ||
+ | tft.setCursor(194, | ||
+ | tft.print(" | ||
+ | tft.setCursor(194, | ||
+ | tft.print(" | ||
+ | tft.setCursor(194, | ||
+ | tft.print(" | ||
+ | |||
+ | TFTrefresh = false; | ||
+ | } | ||
+ | |||
+ | // Unteruntermenü " | ||
+ | if (menuPage == 41 && TFTrefresh == true) { | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | |||
+ | // Zurück zum Untermenü Informationen | ||
+ | tft.fillCircle(20, | ||
+ | |||
+ | TFTrefresh = false; | ||
+ | } | ||
+ | |||
+ | if (menuPage == 41 && ((unsigned long)(currentMillis - previousMillisTFTScreen) >= intervalTFTScreen)) { | ||
+ | intervalTFTScreen = 50; | ||
+ | |||
+ | tft.setFont(); | ||
+ | tft.setTextSize(1); | ||
+ | |||
+ | // Datenausgabe | ||
+ | tft.setFont(); | ||
+ | tft.setTextSize(1); | ||
+ | |||
+ | if (DCFtimesignalFound == false){ | ||
+ | tft.setCursor(60, | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | tft.setCursor(60, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.print(noDCFsignal); | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | } | ||
+ | else { | ||
+ | tft.setCursor(60, | ||
+ | tft.setTextColor(white, | ||
+ | tft.println(" | ||
+ | tft.setCursor(60, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.print(lastDCFsignal); | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | } | ||
+ | |||
+ | tft.setCursor(60, | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | tft.setCursor(60, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.print(receivedDCFsignals); | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | |||
+ | tft.setCursor(60, | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | tft.setCursor(60, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.print(DCFsuccessRate); | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | |||
+ | tft.setCursor(60, | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.print(millis()/ | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | |||
+ | |||
+ | tft.fillRect(60, | ||
+ | tft.setCursor(60, | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.print(flankUp-PreviousflankUp); | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.print(flankDown - flankUp); | ||
+ | |||
+ | previousMillisTFTScreen = currentMillis; | ||
+ | } | ||
+ | |||
+ | // Unteruntermenü " | ||
+ | if (menuPage == 42 && TFTrefresh == true) { | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | |||
+ | // Zurück zum Untermenü Informationen | ||
+ | tft.fillCircle(20, | ||
+ | |||
+ | TFTrefresh = false; | ||
+ | } | ||
+ | |||
+ | if (menuPage == 42 && ((unsigned long)(currentMillis - previousMillisTFTScreen) >= intervalTFTScreen)) { | ||
+ | intervalTFTScreen = 50; | ||
+ | |||
+ | // Datenausgabe | ||
+ | tft.setFont(); | ||
+ | tft.setTextSize(1); | ||
+ | |||
+ | tft.setCursor(60, | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | tft.setCursor(60, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.print(accelX); | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.print(accelY); | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.print(accelZ); | ||
+ | |||
+ | tft.setCursor(60, | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | tft.setCursor(60, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.print(roll); | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.print(pitch); | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.print(heading); | ||
+ | |||
+ | previousMillisTFTScreen = currentMillis; | ||
+ | } | ||
+ | |||
+ | // Unteruntermenü " | ||
+ | if (menuPage == 45 && TFTrefresh == true) { | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | |||
+ | // Zurück zum Untermenü Informationen | ||
+ | tft.fillCircle(20, | ||
+ | |||
+ | TFTrefresh = false; | ||
+ | } | ||
+ | |||
+ | if (menuPage == 45 && ((unsigned long)(currentMillis - previousMillisTFTScreen) >= intervalTFTScreen)) { | ||
+ | intervalTFTScreen = 500; | ||
+ | |||
+ | // Datenausgabe | ||
+ | tft.setFont(); | ||
+ | tft.setTextSize(1); | ||
+ | |||
+ | tft.setCursor(60, | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.println(ir); | ||
+ | tft.setCursor(60, | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.println(full); | ||
+ | tft.setCursor(60, | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.println(full - ir); | ||
+ | tft.setCursor(60, | ||
+ | tft.setTextColor(white, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(red, | ||
+ | tft.println(lux); | ||
+ | |||
+ | previousMillisTFTScreen = currentMillis; | ||
+ | } | ||
+ | |||
+ | // Unteruntermenü " | ||
+ | if (menuPage == 46 && TFTrefresh == true) { | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | |||
+ | // Zurück zum Untermenü Informationen | ||
+ | tft.fillCircle(20, | ||
+ | |||
+ | // Obere Reihe des Menüs | ||
+ | tft.setTextSize(1); | ||
+ | tft.setTextColor(black, | ||
+ | tft.setCursor(35, | ||
+ | tft.print(" | ||
+ | tft.setCursor(145, | ||
+ | tft.print(" | ||
+ | |||
+ | // Bereich der Datenausgabe | ||
+ | tft.print(" | ||
+ | |||
+ | TFTrefresh = false; | ||
+ | } | ||
+ | |||
+ | // Unteruntermenü " | ||
+ | if (menuPage == 48 && TFTrefresh == true) { | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | |||
+ | // Zurück zum Untermenü Informationen | ||
+ | tft.fillCircle(20, | ||
+ | |||
+ | // Obere Reihe des Menüs | ||
+ | tft.setTextSize(1); | ||
+ | tft.setTextColor(black, | ||
+ | tft.setCursor(35, | ||
+ | tft.print(" | ||
+ | tft.setCursor(145, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(white, | ||
+ | tft.setCursor(255, | ||
+ | tft.print(" | ||
+ | tft.setCursor(245, | ||
+ | tft.print(" | ||
+ | |||
+ | // Bereich der Datenausgabe | ||
+ | tft.print(" | ||
+ | tft.print(millis() / 60000); | ||
+ | tft.print(" | ||
+ | |||
+ | TFTrefresh = false; | ||
+ | } | ||
+ | |||
+ | // Untermenü " | ||
+ | if (menuPage == 5 && TFTrefresh == true) { | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | |||
+ | // Zurück zum Hauptmenü | ||
+ | tft.fillCircle(20, | ||
+ | |||
+ | // Wecker stellen | ||
+ | tft.fillCircle(105, | ||
+ | tft.fillCircle(214, | ||
+ | tft.fillCircle(105, | ||
+ | tft.fillCircle(214, | ||
+ | |||
+ | tft.setFont(& | ||
+ | tft.setTextColor(white, | ||
+ | tft.setCursor(125, | ||
+ | tft.print(" | ||
+ | |||
+ | tft.fillRect(80, | ||
+ | tft.setFont(& | ||
+ | tft.setTextColor(red, | ||
+ | tft.setCursor(90, | ||
+ | if(alarmHour < 10) { | ||
+ | tft.print(' | ||
+ | } | ||
+ | tft.print(alarmHour); | ||
+ | |||
+ | tft.setCursor(159, | ||
+ | tft.print(":" | ||
+ | |||
+ | tft.fillRect(185, | ||
+ | tft.setCursor(195, | ||
+ | if(alarmMinute < 10) { | ||
+ | tft.print(' | ||
+ | } | ||
+ | tft.print(alarmMinute); | ||
+ | |||
+ | tft.setFont(& | ||
+ | tft.setTextColor(white, | ||
+ | tft.setCursor(120, | ||
+ | if (alarmMode == 0) { | ||
+ | tft.print(" | ||
+ | } | ||
+ | else if (alarmMode == 1) { | ||
+ | tft.print(" | ||
+ | } | ||
+ | |||
+ | // Weiter zur Auswahl des Programmmodus | ||
+ | tft.fillCircle(299, | ||
+ | |||
+ | tft.setTextSize(0); | ||
+ | |||
+ | TFTrefresh = false; | ||
+ | } | ||
+ | |||
+ | // Unteruntermenü " | ||
+ | if (menuPage == 51 && TFTrefresh == true) { | ||
+ | // Zurück zum " | ||
+ | tft.fillCircle(20, | ||
+ | |||
+ | // Optionen | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(84, | ||
+ | if (alarmMode == 0) { | ||
+ | tft.fillCircle(89, | ||
+ | tft.setTextColor(white); | ||
+ | } | ||
+ | else { | ||
+ | tft.fillCircle(89, | ||
+ | tft.setTextColor(red); | ||
+ | } | ||
+ | tft.print(" | ||
+ | |||
+ | tft.setCursor(84, | ||
+ | if (alarmMode == 1) { | ||
+ | tft.fillCircle(89, | ||
+ | tft.setTextColor(white); | ||
+ | } | ||
+ | else { | ||
+ | tft.fillCircle(89, | ||
+ | tft.setTextColor(red); | ||
+ | } | ||
+ | tft.print(" | ||
+ | |||
+ | tft.setCursor(84, | ||
+ | if (alarmMode == 2) { | ||
+ | tft.fillCircle(89, | ||
+ | tft.setTextColor(white); | ||
+ | } | ||
+ | else { | ||
+ | tft.fillCircle(89, | ||
+ | tft.setTextColor(red); | ||
+ | } | ||
+ | tft.print(" | ||
+ | |||
+ | tft.setCursor(84, | ||
+ | if (alarmMode == 3) { | ||
+ | tft.fillCircle(89, | ||
+ | tft.setTextColor(white); | ||
+ | } | ||
+ | else { | ||
+ | tft.fillCircle(89, | ||
+ | tft.setTextColor(red); | ||
+ | } | ||
+ | tft.print(" | ||
+ | |||
+ | TFTrefresh = false; | ||
+ | } | ||
+ | |||
+ | // Untermenü " | ||
+ | if (menuPage == 7 && TFTrefresh == true) { | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | |||
+ | // Wecker aus | ||
+ | tft.fillRect(0, | ||
+ | tft.setTextColor(black, | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(85, | ||
+ | tft.print(" | ||
+ | |||
+ | // Schlummern | ||
+ | tft.fillRect(214, | ||
+ | tft.setTextColor(black, | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(220, | ||
+ | tft.print(" | ||
+ | |||
+ | TFTrefresh = false; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | touch = false; | ||
+ | touch2 = false; | ||
+ | |||
+ | //Speichere die aktuelle Zeit in die zughörige Variable | ||
+ | | ||
+ | } | ||
+ | |||
+ | // Ausgabe an die serielle Schnittstelle | ||
+ | if ((unsigned long)(currentMillis - previousMillisSerialPrint) >= intervalSerialPrint) { | ||
+ | |||
+ | // Gibt die aktuelle Zeit aus | ||
+ | Serial.print(hour()); | ||
+ | printDigits(minute()); | ||
+ | printDigits(second()); | ||
+ | Serial.print(" | ||
+ | Serial.print(day()); | ||
+ | Serial.print(" | ||
+ | Serial.print(month()); | ||
+ | Serial.print(" | ||
+ | Serial.print(year()); | ||
+ | Serial.print(" | ||
+ | Serial.print(weekday()); | ||
+ | printDCFsyncTime(); | ||
+ | |||
+ | Serial.print(" | ||
+ | Serial.print(menuPage); | ||
+ | Serial.print("; | ||
+ | Serial.print(TFTbrightness); | ||
+ | |||
+ | Serial.print("; | ||
+ | Serial.print(receivedDCFsignals); | ||
+ | |||
+ | // Display the results (acceleration is measured in m/s^2) | ||
+ | Serial.print("; | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | |||
+ | // ' | ||
+ | Serial.print(F("; | ||
+ | Serial.print(roll); | ||
+ | Serial.print(F(" | ||
+ | Serial.print(pitch); | ||
+ | Serial.print(F(" | ||
+ | Serial.print(heading); | ||
+ | Serial.print(F("" | ||
+ | |||
+ | Serial.println(); | ||
+ | //Speichere die aktuelle Zeit in die zughörige Variable | ||
+ | previousMillisSerialPrint = currentMillis; | ||
+ | } | ||
+ | |||
+ | // Misst die Periode und Pusweite des vom DCF77-Modul empfangenen Signals in Millisekunden | ||
+ | if ((unsigned long)(currentMillis - previousMillisDCFPulseLength) >= intervalDCFPulseLength) { | ||
+ | |||
+ | int sensorValue = !digitalRead(DCF_PIN); | ||
+ | if (sensorValue) { | ||
+ | if (!Up) { | ||
+ | flankUp=millis(); | ||
+ | Up = true; | ||
+ | } | ||
+ | } else { | ||
+ | if (Up) { | ||
+ | flankDown=millis(); | ||
+ | Serial.print(" | ||
+ | Serial.print(flankUp-PreviousflankUp); | ||
+ | Serial.print(" | ||
+ | Serial.println(flankDown - flankUp); | ||
+ | PreviousflankUp = flankUp; | ||
+ | Up = false; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | //Speichere die aktuelle Zeit in die zughörige Variable | ||
+ | previousMillisDCFPulseLength = currentMillis; | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | time_t getTeensy3Time() | ||
+ | { | ||
+ | return Teensy3Clock.get(); | ||
+ | } | ||
+ | |||
+ | |||
+ | /* code to process time sync messages from the serial port */ | ||
+ | #define TIME_HEADER | ||
+ | |||
+ | unsigned long processSyncMessage() { | ||
+ | time_t pctime = 0L; | ||
+ | //unsigned long pctime = 0L; | ||
+ | |||
+ | if(Serial.find(TIME_HEADER)) { | ||
+ | | ||
+ | | ||
+ | if( pctime < DefaultTime) { // check the value is a valid time (greater than Nov 1 2016) | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | return pctime; | ||
+ | } | ||
+ | |||
+ | |||
+ | void tftprintDigits(int digits) { | ||
+ | // utility function for digital clock display: prints preceding colon and leading 0 | ||
+ | tft.print(":" | ||
+ | if(digits < 10) | ||
+ | tft.print(' | ||
+ | tft.print(digits); | ||
+ | } | ||
+ | |||
+ | |||
+ | void printDigits(int digits) { | ||
+ | // utility function for digital clock display: prints preceding colon and leading 0 | ||
+ | Serial.print(":" | ||
+ | if(digits < 10) | ||
+ | Serial.print(' | ||
+ | Serial.print(digits); | ||
+ | } | ||
+ | |||
+ | |||
+ | void tftprintDCFsyncTime() { | ||
+ | if (DCFtimesignalFound == false){ | ||
+ | tft.println(" | ||
+ | tft.print(noDCFsignal); | ||
+ | tft.print(" | ||
+ | } | ||
+ | else { | ||
+ | tft.println(" | ||
+ | tft.print(lastDCFsignal); | ||
+ | tft.print(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | void printDCFsyncTime() { | ||
+ | if (DCFtimesignalFound == false){ | ||
+ | Serial.print(" | ||
+ | Serial.print(noDCFsignal); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | else { | ||
+ | Serial.print(" | ||
+ | Serial.print(lastDCFsignal); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | void tftprintDCFsyncCycle() { | ||
+ | if (DCFtimesignalFound == false){ | ||
+ | tft.println(" | ||
+ | tft.print(noDCFsignal / 60); | ||
+ | tft.print(" | ||
+ | } | ||
+ | else { | ||
+ | tft.println(" | ||
+ | tft.print(lastDCFsignal /60); | ||
+ | tft.print(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | /* | ||
+ | // Die Funktion alarmFunktion aktiviert einen Weckalarm, wenn der alarmMode ungleich " | ||
+ | void alarmFunction() { | ||
+ | if (alarmMode != 0) { | ||
+ | alarmRunning = true; | ||
+ | } | ||
+ | } | ||
+ | */ | ||
+ | |||
+ | void StartupScreen() { | ||
+ | // Zeigt einen Startup-Screen | ||
+ | tft.println(" | ||
+ | tft.println(" | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Der Sketch verwendet 77.364 Bytes (7%) des Programmspeicherplatzes. Das Maximum sind 1.048.576 Bytes. | ||
+ | Globale Variablen verwenden 6.376 Bytes (2%) des dynamischen Speichers, 255.768 Bytes für lokale Variablen verbleiben. Das Maximum sind 262.144 Bytes. | ||
+ | |||
+ | {{tag> |
arduino/schlafphasenwecker/programmversion_0.4.1482144981.txt.gz · Zuletzt geändert: 18.05.2023 12:16 (Externe Bearbeitung)