arduino:schlafphasenwecker:programmversion_0.3
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
arduino:schlafphasenwecker:programmversion_0.3 [17.12.2016 22:08] – Frickelpiet | arduino:schlafphasenwecker:programmversion_0.3 [18.05.2023 12:34] (aktuell) – Externe Bearbeitung 127.0.0.1 | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
====== Schlafphasenwecker Programmversion 0.3 ====== | ====== Schlafphasenwecker Programmversion 0.3 ====== | ||
- | Da viele weckertypische Funktionen (zum Beispiel eine Weckfunktion) eine Eingabemöglichkeit erfordern, legt diese Programmversion den Fokus auf das grafische Menü. | + | <box 30% green right|**Achtung**> |
* Der Touchsensor löst erst aus, wenn es losgelassen wird. | * Der Touchsensor löst erst aus, wenn es losgelassen wird. | ||
Zeile 12: | Zeile 12: | ||
* Die Variable DCFsuccessRate wird falsch berechnet. | * Die Variable DCFsuccessRate wird falsch berechnet. | ||
* Die Ansteuerung des TFT-Screens benötigt keine eigene Schleife. | * Die Ansteuerung des TFT-Screens benötigt keine eigene Schleife. | ||
+ | * https:// | ||
+ | * Sekunden als hh:mm:ss ausgeben: http:// | ||
- | Sekunden als hh:mm:ss ausgeben: | + | Hilfreiche Links: |
- | * http://forum.arduino.cc/index.php? | + | * https://learn.adafruit.com/ahrs-for-adafruits-9-dof-10-dof-breakout/ |
- | Tags: # | + | < |
+ | // Schlafphasenwecker Version 0.2 | ||
+ | |||
+ | // Bibliotheken einbinden | ||
+ | #include < | ||
+ | #include < | ||
+ | #include " | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include " | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | //#include < | ||
+ | //#include < | ||
+ | |||
+ | // 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 | ||
+ | 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. | ||
+ | |||
+ | 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; | ||
+ | |||
+ | boolean TFTbackLightStatus = 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 = 20000; // Zeit in Millisekunden, | ||
+ | unsigned long TFTbackLightTime = 0; | ||
+ | boolean touchtouched2 = false; | ||
+ | boolean forceRefresh = 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 = 0; // 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 previousMillisTFTScreen = 0; | ||
+ | unsigned long previousMillisTouchScreen = 0; | ||
+ | unsigned long previousMillisSensorData = 0; | ||
+ | unsigned long previousMillisSerialPrint = 0; | ||
+ | |||
+ | |||
+ | // Definiert die Intervalle für die IF-Abfragen in Millisekunden | ||
+ | const unsigned long intervalSetRTC = 1000; // Delay für Holen der Zeit | ||
+ | const unsigned long intervalTFTScreen = 100; // Delay für Anteuerung des TFT-Screens | ||
+ | const unsigned long intervalTouchScreen = 50; // Delay für Anteuerung des kapazitiven Touchsreens | ||
+ | const unsigned long intervalSensorData = 1000; // Delay für Auslesen der Sensoren | ||
+ | const unsigned long intervalSerialPrint = 1000; // Delay für serielle Ausgabe | ||
+ | |||
+ | |||
+ | 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_500MS); | ||
+ | // tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS); | ||
+ | |||
+ | |||
+ | // Startet die Abfrage des DCF77-Moduls | ||
+ | DCF.Start(); | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | |||
+ | |||
+ | // Initialisiert den TSL2591 | ||
+ | tsl.begin(); | ||
+ | |||
+ | // Die folgenden Einstellungen sorgen dafür, dass das TFT Backlight nach dem Systemstart abdunkelt. | ||
+ | // (Die Variable TFTbackLightTime wird ansonsten erst nach dem Berühren des Touchscreens auf millis gesetzt.) | ||
+ | TFTbackLightTime = millis(); | ||
+ | TFTbackLightStatus = true; | ||
+ | } | ||
+ | |||
+ | |||
+ | 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; | ||
+ | } | ||
+ | |||
+ | |||
+ | // 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; | ||
+ | |||
+ | //Speichere die aktuelle Zeit in die zughörige Variable | ||
+ | previousMillisSensorData = currentMillis; | ||
+ | } | ||
+ | |||
+ | |||
+ | // Bildschirmanzeige | ||
+ | if (((unsigned long)(currentMillis - previousMillisTFTScreen) >= intervalTFTScreen) && (previousmenuPage != menuPage || forceRefresh == true)) { | ||
+ | |||
+ | forceRefresh = false; | ||
+ | |||
+ | // 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) { | ||
+ | // Linke Spalte des Menüs | ||
+ | tft.fillRect(0, | ||
+ | tft.fillRect(0, | ||
+ | tft.fillRect(0, | ||
+ | tft.fillRect(0, | ||
+ | |||
+ | tft.setTextColor(black, | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(10, | ||
+ | tft.print(" | ||
+ | tft.setCursor(10, | ||
+ | tft.print(" | ||
+ | tft.setCursor(10, | ||
+ | tft.print(" | ||
+ | tft.setCursor(10, | ||
+ | tft.print(" | ||
+ | |||
+ | //Rechte Spalte des Menüs | ||
+ | |||
+ | } | ||
+ | |||
+ | // Untermenü " | ||
+ | if (menuPage == 5) { | ||
+ | // Zurück zum Hauptmenü | ||
+ | tft.fillRect(0, | ||
+ | |||
+ | // Wecker stellen | ||
+ | tft.setTextColor(white, | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(50, | ||
+ | tft.print(" | ||
+ | } | ||
+ | |||
+ | // Untermenü " | ||
+ | if (menuPage == 1) { | ||
+ | // Zurück zum Hauptmenü | ||
+ | tft.fillRect(0, | ||
+ | |||
+ | // Snoozle stellen | ||
+ | tft.setTextColor(white, | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(50, | ||
+ | tft.print(" | ||
+ | } | ||
+ | |||
+ | // Untermenü " | ||
+ | if (menuPage == 2) { | ||
+ | // Zurück zum Hauptmenü | ||
+ | tft.fillRect(0, | ||
+ | |||
+ | // Effekte einstellen | ||
+ | tft.setTextColor(white, | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(50, | ||
+ | tft.print(" | ||
+ | } | ||
+ | |||
+ | // Untermenü " | ||
+ | if (menuPage == 3) { | ||
+ | // Zurück zum Hauptmenü | ||
+ | tft.fillRect(0, | ||
+ | |||
+ | // Einstellungen stellen | ||
+ | tft.setTextColor(white, | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(50, | ||
+ | tft.print(" | ||
+ | } | ||
+ | |||
+ | // Untermenü " | ||
+ | if (menuPage == 4) { | ||
+ | // Zurück zum Hauptmenü | ||
+ | tft.fillRect(0, | ||
+ | |||
+ | // Linke Spalte | ||
+ | tft.fillRect(51, | ||
+ | tft.fillRect(51, | ||
+ | tft.fillRect(51, | ||
+ | tft.fillRect(51, | ||
+ | |||
+ | tft.setTextColor(black, | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(61, | ||
+ | tft.print(" | ||
+ | tft.setCursor(61, | ||
+ | tft.print(" | ||
+ | tft.setCursor(61, | ||
+ | tft.print(" | ||
+ | tft.setCursor(61, | ||
+ | tft.print(" | ||
+ | |||
+ | // Rechte Spalte | ||
+ | tft.fillRect(186, | ||
+ | tft.fillRect(186, | ||
+ | tft.fillRect(186, | ||
+ | tft.fillRect(186, | ||
+ | |||
+ | tft.setTextColor(black, | ||
+ | tft.setFont(& | ||
+ | tft.setCursor(196, | ||
+ | tft.print(" | ||
+ | tft.setCursor(196, | ||
+ | tft.print(" | ||
+ | tft.setCursor(196, | ||
+ | tft.print(" | ||
+ | tft.setCursor(196, | ||
+ | tft.print(" | ||
+ | } | ||
+ | |||
+ | // Unteruntermenü " | ||
+ | if (menuPage == 41) { | ||
+ | // Zurück zum Untermenü Informationen | ||
+ | tft.fillRect(0, | ||
+ | |||
+ | 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(" | ||
+ | |||
+ | forceRefresh = true; | ||
+ | } | ||
+ | |||
+ | // Unteruntermenü " | ||
+ | if (menuPage == 42) { | ||
+ | // Zurück zum Untermenü Informationen | ||
+ | tft.fillRect(0, | ||
+ | |||
+ | // 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); | ||
+ | |||
+ | |||
+ | forceRefresh = true; | ||
+ | } | ||
+ | |||
+ | // Unteruntermenü " | ||
+ | if (menuPage == 45) { | ||
+ | // Zurück zum Untermenü Informationen | ||
+ | tft.fillRect(0, | ||
+ | |||
+ | // 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(tsl.calculateLux(full, | ||
+ | |||
+ | forceRefresh = true; | ||
+ | } | ||
+ | |||
+ | // Unteruntermenü " | ||
+ | if (menuPage == 46) { | ||
+ | // Obere Reihe des Menüs | ||
+ | tft.fillRect(0, | ||
+ | tft.setTextSize(1); | ||
+ | tft.setTextColor(black, | ||
+ | tft.setCursor(35, | ||
+ | tft.print(" | ||
+ | tft.setCursor(145, | ||
+ | tft.print(" | ||
+ | |||
+ | // Bereich der Datenausgabe | ||
+ | tft.print(" | ||
+ | } | ||
+ | |||
+ | // Unteruntermenü " | ||
+ | if (menuPage == 48) { | ||
+ | // Obere Reihe des Menüs | ||
+ | tft.fillRect(0, | ||
+ | tft.fillRect(107, | ||
+ | |||
+ | 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(" | ||
+ | } | ||
+ | |||
+ | // Unteruntermenü " | ||
+ | if (menuPage == 7) { | ||
+ | // Obere Reihe des Menüs | ||
+ | tft.fillRect(0, | ||
+ | tft.fillRect(0, | ||
+ | |||
+ | tft.setTextSize(3); | ||
+ | tft.setTextColor(black, | ||
+ | tft.setCursor(150, | ||
+ | tft.print(" | ||
+ | tft.setCursor(180, | ||
+ | tft.print(" | ||
+ | tft.setTextColor(black, | ||
+ | tft.setCursor(245, | ||
+ | tft.print(" | ||
+ | } | ||
+ | |||
+ | // Damit der TFT-Screen nicht flackert, wird diese Schleife nur ausgeführt, | ||
+ | previousmenuPage = menuPage; | ||
+ | |||
+ | //Speichere die aktuelle Zeit in die zughörige Variable | ||
+ | previousMillisTFTScreen = currentMillis; | ||
+ | } | ||
+ | |||
+ | |||
+ | // Touchscreen | ||
+ | if ((unsigned long)(currentMillis - previousMillisTouchScreen) >= intervalTouchScreen) { | ||
+ | |||
+ | // Wait for a touch | ||
+ | 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; | ||
+ | |||
+ | // | ||
+ | TFTbackLightTime = millis(); | ||
+ | touchtouched2 = true; | ||
+ | |||
+ | // Damit der Touchsenso erst beim Loslassen des Screens eine Aktion auslöst, darf so lange er gedrückt wird nichts passieren. | ||
+ | // Daher wird touchtime so lange auf die aktuelle Zeit gesetzt, wie der Touchscreen gedrückt wird. | ||
+ | // Ausgelöst wird die Aktion erst dann, wenn der Touchscreen nicht mehr gedrückt ist und die bebouncetime verstrichen ist. | ||
+ | touchtime = millis(); | ||
+ | touchtouched = true; | ||
+ | } | ||
+ | |||
+ | |||
+ | // 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 && touchtouched == true && TFTbackLightStatus == true && (millis() - touchtime > debouncetime)) { // Wenn Menüseite 0 ausgewählt und der Touchscreen berührt wird und die debouncetime verstrichen 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; | ||
+ | } | ||
+ | touchtouched = false; | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | } | ||
+ | |||
+ | // Menü Snoozle | ||
+ | if (menuPage == 1 && touchtouched == true && TFTbackLightStatus == true && (millis() - touchtime > debouncetime)) { | ||
+ | // 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; | ||
+ | } | ||
+ | touchtouched = false; | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | } | ||
+ | |||
+ | // Menü Ziffernblatt | ||
+ | if (menuPage == 2 && touchtouched == true && (millis() - touchtime > debouncetime)) { | ||
+ | // 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; | ||
+ | } | ||
+ | touchtouched = false; | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | } | ||
+ | |||
+ | // Menü Einstellungen | ||
+ | if (menuPage == 3 && touchtouched == true && TFTbackLightStatus == true && (millis() - touchtime > debouncetime)) { | ||
+ | // 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; | ||
+ | } | ||
+ | touchtouched = false; | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | } | ||
+ | |||
+ | // Menü Informationen | ||
+ | if (menuPage == 4 && touchtouched == true && TFTbackLightStatus == true && (millis() - touchtime > debouncetime)) { | ||
+ | // 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; | ||
+ | } | ||
+ | */ | ||
+ | touchtouched = false; | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | } | ||
+ | |||
+ | // Untermenü DCF77 Zeitsignal | ||
+ | if (menuPage == 41 && touchtouched == true && TFTbackLightStatus == true && (millis() - touchtime > debouncetime)) { | ||
+ | // 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; | ||
+ | } | ||
+ | touchtouched = false; | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | } | ||
+ | |||
+ | // Untermenü TSL2591 Sensor | ||
+ | if (menuPage == 45 && touchtouched == true && TFTbackLightStatus == true && (millis() - touchtime > debouncetime)) { | ||
+ | // 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; | ||
+ | } | ||
+ | touchtouched = false; | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | } | ||
+ | |||
+ | // Untermenü TSL303 Sensor | ||
+ | if (menuPage == 42 && touchtouched == true && TFTbackLightStatus == true && (millis() - touchtime > debouncetime)) { | ||
+ | // 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; | ||
+ | } | ||
+ | touchtouched = false; | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | } | ||
+ | |||
+ | // Menü Wecker stellen | ||
+ | if (menuPage == 5 && touchtouched == true && TFTbackLightStatus == true && (millis() - touchtime > debouncetime)) { | ||
+ | // 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; | ||
+ | } | ||
+ | touchtouched = false; | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | } | ||
+ | |||
+ | // Das TFT Backlight soll beim Berühren des Touchscreens eingeschaltet werden. Nach einer eingestellten Zeit soll die Beleuchtung wieder ausgeschaltet werden. | ||
+ | // Damit Eigentlich soll der Touchsensor bei der ersten Berührung nur eingeschaltet werden, und erst wenn das Licht an ist, d.h. bei der zweiten Berührung Menüpunkte auswählen. | ||
+ | // Das Funktioniert aber noch nicht. | ||
+ | if (touchtouched2 == true && (millis() - touchtime > debouncetime)) { | ||
+ | if (millis() <= TFTbackLightTime + TFTbackLightdelay) { | ||
+ | TFTbackLightStatus = true; | ||
+ | TFTbrightness = 255; | ||
+ | } | ||
+ | analogWrite(TFTbackLightPin, | ||
+ | touchtouched2 = false; | ||
+ | } | ||
+ | if ((millis() > TFTbackLightTime + TFTbackLightdelay) && TFTbackLightStatus == true) { | ||
+ | TFTbrightness = TFTbrightness - 1; | ||
+ | if (TFTbrightness == 0) { | ||
+ | TFTbackLightStatus = false; | ||
+ | tft.fillScreen(ILI9341_BLACK); | ||
+ | } | ||
+ | analogWrite(TFTbackLightPin, | ||
+ | } | ||
+ | |||
+ | //Speichere die aktuelle Zeit in die zughörige Variable | ||
+ | previousMillisTouchScreen = currentMillis; | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | // 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()); | ||
+ | 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; | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | 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(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | void StartupScreen() { | ||
+ | // Zeigt einen Startup-Screen | ||
+ | tft.println(" | ||
+ | tft.println(" | ||
+ | } | ||
+ | </ | ||
+ | Der Sketch verwendet 62.504 Bytes (5%) des Programmspeicherplatzes. Das Maximum sind 1.048.576 Bytes. | ||
+ | Globale Variablen verwenden 6.496 Bytes (2%) des dynamischen Speichers, 255.648 Bytes für lokale Variablen verbleiben. Das Maximum sind 262.144 Bytes. | ||
+ | |||
+ | {{tag>Arduino Schlafphasenwecker |
arduino/schlafphasenwecker/programmversion_0.3.1482008930.txt.gz · Zuletzt geändert: 18.05.2023 12:16 (Externe Bearbeitung)