cbcx

Dependencies:   DmTftLibrary mbed

Fork of LCD_Proj by Tobias Fuchsbichler

Revision:
3:03c08a612220
Parent:
2:e1b98fac05ed
Child:
4:0d4286278f41
diff -r e1b98fac05ed -r 03c08a612220 main.cpp
--- a/main.cpp	Mon Dec 21 15:22:03 2015 +0000
+++ b/main.cpp	Mon Jan 25 12:42:52 2016 +0000
@@ -15,7 +15,7 @@
  *****************************************************************************/
 
 #include "mbed.h"
-#include "bild.h"
+#include "bild.h"   //Bilder mit einbinden
 
 #include "DmTftHX8353C.h"
 #include "DmTftS6D0164.h"
@@ -76,7 +76,6 @@
 DigitalInOut csFlash(DM_PIN_CS_FLASH, PIN_OUTPUT, PullUp, 1);
 #endif
 
-PwmOut pwmRTC(p23); // RTC test PWM
 /******************************************************************************
  * Global variables
  *****************************************************************************/
@@ -87,14 +86,14 @@
 uint16_t h = tft.height();
 
 bool down=false;
-
 time_t secondsSince1970;
- char timeString[20];
+char timeString[20];
 
 /******************************************************************************
  * Local functions
  *****************************************************************************/
 
+//Farben definieren
 /*
 #define RED     0xf800
 #define GREEN   0x07e0
@@ -120,35 +119,47 @@
 #define GreenYellow     0xAFE5      /* 173, 255,  47 */
 #define Pink            0xF81F
 
+//Ticker initialisieren
 Ticker Tick;
 
+//Globale Variablen
 float a;
 int msek;
 int sek;
 int min;
 int stund;
+int lsek;
+int lmin;
+int lstund;
 bool mode;
+bool lhilf=false;
 
+//Funktionsaufruf des Tickersinterrupts der Stoppuhr
 void zaehl()
 {
     if(mode==true) {
         msek++;
+        //msek in sek
         if(msek==100) {
             sek++;
             msek=0;
 
         }
 
+        //sek in min
         if(sek==60) {
             min++;
             sek=0;
 
         }
 
+        //min in stund
         if(min==60) {
             stund++;
             min=0;
         }
+        
+        //stund reseten
         if(stund==24) {
             msek=0;
             sek=0;
@@ -160,19 +171,35 @@
 
 }
 
+//"Falsche" Zwischenzeit stoppen
+void lap()
+{
+
+    tft.drawNumber(78,250,stund,2,1);
+    tft.drawString(94, 250, ":");
+    tft.drawNumber(102,250,min,2,1);
+    tft.drawString(118, 250, ":");
+    tft.drawNumber(126,250,sek,2,1);
+    tft.drawString(142, 250, ":");
+    tft.drawNumber(150,250,msek,2,1);
+
+}
+
+//Stoppuhr reseten
 void reset()
 {
     msek=0;
     sek=0;
     min=0;
     stund=0;
+    lap();
 }
 
-
+//Startseite zeichnen
 void drawButtons()
 {
     tft.clearScreen(BLACK);
-    //Rectangles
+//Rectangles
     tft.drawRectangle(25, 285, 74, 310,WHITE);
     tft.drawRectangle(95, 285, 144, 310,WHITE);
     tft.drawRectangle(165, 285,214, 310,WHITE);
@@ -192,18 +219,53 @@
 
 
 }
+
+
+//Einstellungen der RTC(Real Time Clock)
 void RTC_SETUP()
 {
     tft.clearScreen(BLACK);
 
+    lhilf=true;
+
     tft.drawImage(176,0,64,32,accept);
+
+    tft.drawImage(20,80,32,32,arrow_up);
+    tft.drawImage(104,80,32,32,arrow_up);
+    tft.drawImage(188,80,32,32,arrow_up);
+
+    tft.drawImage(20,140,32,32,arrow_down);
+    tft.drawImage(104,140,32,32,arrow_down);
+    tft.drawImage(188,140,32,32,arrow_down);
+    
     tft.drawString(84, 30, "SETTINGS");
-    
+
     while(1) {
         secondsSince1970 = time(NULL);
-        strftime(timeString, 20, "%H:%M:%S", localtime(&secondsSince1970));
-        tft.drawString(50, 50, timeString);
-        
+
+        tft.drawNumber(28, 118,lstund,2,1);
+        tft.drawNumber(112, 118, lmin,2,1);
+        tft.drawNumber(196, 118, lsek,2,1);
+
+        if(lstund==9&&lmin==1&&lsek==1&&lhilf==true)
+        {
+            //cages
+            tft.drawImage(0,200,60,60,cage);
+            tft.drawImage(60,200,60,60,cage);
+            tft.drawImage(120,200,60,60,cage);
+            tft.drawImage(180,200,60,60,cage);
+            
+            tft.drawImage(0,260,60,60,cage);
+            tft.drawImage(60,260,60,60,cage);
+            tft.drawImage(120,260,60,60,cage);
+            tft.drawImage(180,260,60,60,cage);
+            
+            wait(2);
+            
+            tft.fillRectangle(0,200,240,320,BLACK);
+            lhilf=false;
+        }
+
         touch.readTouchData(x, y, down);
         if(down==true&&x>=208&&x<=240&&y>=0&&y<=32) {
             wait(0.25);
@@ -211,7 +273,66 @@
             return;
         }
 
+        //Stunden Konfiguration
+        if(down==true&&x>=20&&x<=52&&y>=80&&y<=112) {
+            lstund++;
+            if(lstund>=24)
+                lstund=0;
+            wait(0.25);
+        }
+        if(down==true&&x>=20&&x<=52&&y>=140&&y<=172) {
+            lstund--;
+            if(lstund<0)
+                lstund=23;
+            wait(0.25);
+        }
+
+
+        //Minuten Konfiguration
+        if(down==true&&x>=104&&x<=136&y>=80&&y<=112) {
+            lmin++;
+            if(lmin>=60)
+                lmin=0;
+            wait(0.25);
+        }
+        if(down==true&&x>=104&&x<=136&&y>=140&&y<=172) {
+            lmin--;
+            if(lmin<0)
+                lmin=59;
+            wait(0.25);
+        }
+
+
+        //Sekunden Konfiguration
+        if(down==true&&x>=188&&x<=220&&y>=80&&y<=112) {
+            lsek++;
+            if(lsek>=60)
+                lsek=0;
+            wait(0.25);
+        }
+
+        if(down==true&&x>=188&&x<=220&&y>=140&&y<=172) {
+            lsek--;
+            if(lsek<0)
+                lsek=59;
+            wait(0.25);
+        }
         if(down==true&&x>=176&&x<=208&&y>=0&&y<=32) {
+            struct tm t;
+            t.tm_sec = lsek;    // 0-59
+            t.tm_min = lmin;    // 0-59
+            t.tm_hour = lstund;   // 0-23
+            t.tm_mday = 29;   // 1-31
+            t.tm_mon = 1;     // 0-11
+            t.tm_year = 116;  // year since 1900
+
+
+            // convert to timestamp
+            time_t secondsSince1970 = mktime(&t);
+
+            // Set time and start RTC
+            set_time(secondsSince1970);
+
             wait(0.25);
             drawButtons();
             return;
@@ -228,17 +349,15 @@
 
 int main()
 {
-    pwmRTC.write(0.4);
-    pwmRTC.period(0.0000263);
-   
+
 
     struct tm t;
     t.tm_sec = 00;    // 0-59
     t.tm_min = 12;    // 0-59
     t.tm_hour = 10;   // 0-23
-    t.tm_mday = 21;   // 1-31
-    t.tm_mon = 12;     // 0-11
-    t.tm_year = 115;  // year since 1900
+    t.tm_mday = 29;   // 1-31
+    t.tm_mon = 1;     // 0-11
+    t.tm_year = 116;  // year since 1900
 
     // convert to timestamp
     time_t secondsSince1970 = mktime(&t);
@@ -259,25 +378,42 @@
         tft.drawString(90, 50, timeString);
 
         touch.readTouchData(x, y, down);
+
         if(down==true&&x>=208&&x<=240&&y>=0&&y<=32)
-            RTC_SETUP();
+        {
+            strftime(timeString, 20, "%H", localtime(&secondsSince1970));
+            lstund=atoi(timeString);
+            //atoi: Wandelt string in int um
+            
+            strftime(timeString, 20, "%M", localtime(&secondsSince1970));
+            lmin=atoi(timeString);
 
-        if(down==true&&x>=25&&x<=74&&y>=285&&y<=310)
+            strftime(timeString, 20, "%S", localtime(&secondsSince1970));
+            lsek=atoi(timeString);
+            RTC_SETUP();
+        }
+
+        //Start Stoppuhr
+        if(down==true&&x>=25&&x<=74&&y>=285&&y<=310) {
+            if(mode==true) {
+                lap();
+            }
             mode=true;
-
+        }
+        //Stop Stoppuhr
         if(down==true&&x>=95&&x<=144&&y>=285&&y<=310)
             mode=false;
-
+        //Reset Stoppuhr
         if(down==true&&x>=165&&x<=214&&y>=285&&y<=310)
             reset();
 
-        tft.drawNumber(78,250,stund,2,1);
-        tft.drawString(94, 250, ":");
-        tft.drawNumber(102,250,min,2,1);
-        tft.drawString(118, 250, ":");
-        tft.drawNumber(126,250,sek,2,1);
-        tft.drawString(142, 250, ":");
-        tft.drawNumber(150,250,msek,2,1);
+        tft.drawNumber(78,230,stund,2,1);
+        tft.drawString(94, 230, ":");
+        tft.drawNumber(102,230,min,2,1);
+        tft.drawString(118, 230, ":");
+        tft.drawNumber(126,230,sek,2,1);
+        tft.drawString(142, 230, ":");
+        tft.drawNumber(150,230,msek,2,1);
 
         down=false;
     }