![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
cbcx
Dependencies: DmTftLibrary mbed
Fork of LCD_Proj by
main.cpp@3:03c08a612220, 2016-01-25 (annotated)
- Committer:
- TFuchsbichler
- Date:
- Mon Jan 25 12:42:52 2016 +0000
- Revision:
- 3:03c08a612220
- Parent:
- 2:e1b98fac05ed
- Child:
- 4:0d4286278f41
Projekt LCD Ansteuerung
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TFuchsbichler | 0:dd55ca105ef3 | 1 | /********************************************************************************************** |
TFuchsbichler | 0:dd55ca105ef3 | 2 | Copyright (c) 2014 DisplayModule. All rights reserved. |
TFuchsbichler | 0:dd55ca105ef3 | 3 | |
TFuchsbichler | 0:dd55ca105ef3 | 4 | Redistribution and use of this source code, part of this source code or any compiled binary |
TFuchsbichler | 0:dd55ca105ef3 | 5 | based on this source code is permitted as long as the above copyright notice and following |
TFuchsbichler | 0:dd55ca105ef3 | 6 | disclaimer is retained. |
TFuchsbichler | 0:dd55ca105ef3 | 7 | |
TFuchsbichler | 0:dd55ca105ef3 | 8 | DISCLAIMER: |
TFuchsbichler | 0:dd55ca105ef3 | 9 | THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES |
TFuchsbichler | 0:dd55ca105ef3 | 10 | NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. |
TFuchsbichler | 0:dd55ca105ef3 | 11 | ********************************************************************************************/ |
TFuchsbichler | 0:dd55ca105ef3 | 12 | |
TFuchsbichler | 0:dd55ca105ef3 | 13 | /****************************************************************************** |
TFuchsbichler | 0:dd55ca105ef3 | 14 | * Tested on NUCLEO-F401RE, LPCXpresso11U68, LPCXpresso824-MAX platform. |
TFuchsbichler | 0:dd55ca105ef3 | 15 | *****************************************************************************/ |
TFuchsbichler | 0:dd55ca105ef3 | 16 | |
TFuchsbichler | 0:dd55ca105ef3 | 17 | #include "mbed.h" |
TFuchsbichler | 3:03c08a612220 | 18 | #include "bild.h" //Bilder mit einbinden |
TFuchsbichler | 0:dd55ca105ef3 | 19 | |
TFuchsbichler | 0:dd55ca105ef3 | 20 | #include "DmTftHX8353C.h" |
TFuchsbichler | 0:dd55ca105ef3 | 21 | #include "DmTftS6D0164.h" |
TFuchsbichler | 0:dd55ca105ef3 | 22 | #include "DmTftIli9325.h" |
TFuchsbichler | 0:dd55ca105ef3 | 23 | #include "DmTftIli9341.h" |
TFuchsbichler | 0:dd55ca105ef3 | 24 | #include "DmTftSsd2119.h" |
TFuchsbichler | 0:dd55ca105ef3 | 25 | #include "DmTftRa8875.h" |
TFuchsbichler | 0:dd55ca105ef3 | 26 | #include "DmTouch.h" |
TFuchsbichler | 0:dd55ca105ef3 | 27 | #include "DmTpFt6x06.h" |
TFuchsbichler | 0:dd55ca105ef3 | 28 | |
TFuchsbichler | 0:dd55ca105ef3 | 29 | /****************************************************************************** |
TFuchsbichler | 0:dd55ca105ef3 | 30 | * Typedefs and defines |
TFuchsbichler | 0:dd55ca105ef3 | 31 | *****************************************************************************/ |
TFuchsbichler | 0:dd55ca105ef3 | 32 | |
TFuchsbichler | 0:dd55ca105ef3 | 33 | /* Note that there are restrictions on which platforms that can use printf |
TFuchsbichler | 0:dd55ca105ef3 | 34 | in combinations with the DmTftLibrary. Some platforms (e.g. LPC1549 LPCXpresso) |
TFuchsbichler | 0:dd55ca105ef3 | 35 | use the same pins for USBRX/USBTX and display control. Printing will |
TFuchsbichler | 0:dd55ca105ef3 | 36 | cause the display to not work. Read more about this on the display's notebook |
TFuchsbichler | 0:dd55ca105ef3 | 37 | page. */ |
TFuchsbichler | 0:dd55ca105ef3 | 38 | //#define log(...) printf(__VA_ARGS__) |
TFuchsbichler | 0:dd55ca105ef3 | 39 | #define log(...) |
TFuchsbichler | 0:dd55ca105ef3 | 40 | |
TFuchsbichler | 0:dd55ca105ef3 | 41 | #if 1 |
TFuchsbichler | 0:dd55ca105ef3 | 42 | /* Displays without adapter */ |
TFuchsbichler | 0:dd55ca105ef3 | 43 | #define DM_PIN_SPI_MOSI p5 |
TFuchsbichler | 0:dd55ca105ef3 | 44 | #define DM_PIN_SPI_MISO p6 |
TFuchsbichler | 0:dd55ca105ef3 | 45 | #define DM_PIN_SPI_SCLK p7 |
Nikolas | 1:81d0d835991d | 46 | #define DM_PIN_CS_TOUCH p8 |
TFuchsbichler | 0:dd55ca105ef3 | 47 | #define DM_PIN_CS_TFT p21 |
Nikolas | 1:81d0d835991d | 48 | #define DM_PIN_CS_SDCARD p14 // 23 |
Nikolas | 1:81d0d835991d | 49 | #define DM_PIN_CS_FLASH p10 // 24 |
TFuchsbichler | 0:dd55ca105ef3 | 50 | #else |
TFuchsbichler | 0:dd55ca105ef3 | 51 | /* Displays with adapter */ |
TFuchsbichler | 0:dd55ca105ef3 | 52 | #define DM_PIN_SPI_MOSI p5 |
TFuchsbichler | 0:dd55ca105ef3 | 53 | #define DM_PIN_SPI_MISO p6 |
TFuchsbichler | 0:dd55ca105ef3 | 54 | #define DM_PIN_SPI_SCLK p7 |
Nikolas | 1:81d0d835991d | 55 | #define DM_PIN_CS_TOUCH p8 |
TFuchsbichler | 0:dd55ca105ef3 | 56 | #define DM_PIN_CS_TFT p21 |
Nikolas | 1:81d0d835991d | 57 | #define DM_PIN_CS_SDCARD p14 // 13 |
TFuchsbichler | 0:dd55ca105ef3 | 58 | #endif |
TFuchsbichler | 0:dd55ca105ef3 | 59 | |
TFuchsbichler | 0:dd55ca105ef3 | 60 | /****************************************************************************** |
TFuchsbichler | 0:dd55ca105ef3 | 61 | * Local variables |
TFuchsbichler | 0:dd55ca105ef3 | 62 | *****************************************************************************/ |
TFuchsbichler | 0:dd55ca105ef3 | 63 | |
TFuchsbichler | 2:e1b98fac05ed | 64 | |
TFuchsbichler | 0:dd55ca105ef3 | 65 | /********* TFT DISPLAY INIT *********/ |
TFuchsbichler | 0:dd55ca105ef3 | 66 | DmTftIli9341 tft(p21, p22, p5, p6, p7); /* DmTftIli9341(PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk) DM_TFT28_105 and DM_TFT28_116*/ |
TFuchsbichler | 0:dd55ca105ef3 | 67 | |
TFuchsbichler | 0:dd55ca105ef3 | 68 | /********* TOUCH PANEL INIT *********/ |
TFuchsbichler | 0:dd55ca105ef3 | 69 | |
TFuchsbichler | 0:dd55ca105ef3 | 70 | DmTouch touch(DmTouch::DM_TFT28_105, p5, p6, p7); |
TFuchsbichler | 0:dd55ca105ef3 | 71 | |
TFuchsbichler | 0:dd55ca105ef3 | 72 | DigitalInOut csTouch(DM_PIN_CS_TOUCH, PIN_OUTPUT, PullUp, 1); |
TFuchsbichler | 0:dd55ca105ef3 | 73 | DigitalInOut csDisplay(DM_PIN_CS_TFT, PIN_OUTPUT, PullUp, 1); |
TFuchsbichler | 0:dd55ca105ef3 | 74 | DigitalInOut csSDCard(DM_PIN_CS_SDCARD, PIN_OUTPUT, PullUp, 1); |
TFuchsbichler | 0:dd55ca105ef3 | 75 | #ifdef DM_PIN_CS_FLASH |
TFuchsbichler | 0:dd55ca105ef3 | 76 | DigitalInOut csFlash(DM_PIN_CS_FLASH, PIN_OUTPUT, PullUp, 1); |
TFuchsbichler | 0:dd55ca105ef3 | 77 | #endif |
TFuchsbichler | 0:dd55ca105ef3 | 78 | |
TFuchsbichler | 0:dd55ca105ef3 | 79 | /****************************************************************************** |
TFuchsbichler | 2:e1b98fac05ed | 80 | * Global variables |
TFuchsbichler | 0:dd55ca105ef3 | 81 | *****************************************************************************/ |
TFuchsbichler | 0:dd55ca105ef3 | 82 | |
TFuchsbichler | 2:e1b98fac05ed | 83 | uint16_t x = 0; |
TFuchsbichler | 2:e1b98fac05ed | 84 | uint16_t y = 0; |
TFuchsbichler | 2:e1b98fac05ed | 85 | uint16_t w = tft.width(); |
TFuchsbichler | 2:e1b98fac05ed | 86 | uint16_t h = tft.height(); |
TFuchsbichler | 2:e1b98fac05ed | 87 | |
TFuchsbichler | 2:e1b98fac05ed | 88 | bool down=false; |
TFuchsbichler | 2:e1b98fac05ed | 89 | time_t secondsSince1970; |
TFuchsbichler | 3:03c08a612220 | 90 | char timeString[20]; |
TFuchsbichler | 2:e1b98fac05ed | 91 | |
TFuchsbichler | 0:dd55ca105ef3 | 92 | /****************************************************************************** |
TFuchsbichler | 0:dd55ca105ef3 | 93 | * Local functions |
TFuchsbichler | 0:dd55ca105ef3 | 94 | *****************************************************************************/ |
TFuchsbichler | 0:dd55ca105ef3 | 95 | |
TFuchsbichler | 3:03c08a612220 | 96 | //Farben definieren |
Nikolas | 1:81d0d835991d | 97 | /* |
Nikolas | 1:81d0d835991d | 98 | #define RED 0xf800 |
Nikolas | 1:81d0d835991d | 99 | #define GREEN 0x07e0 |
Nikolas | 1:81d0d835991d | 100 | #define BLUE 0x001f |
Nikolas | 1:81d0d835991d | 101 | #define BLACK 0x0000 |
Nikolas | 1:81d0d835991d | 102 | #define YELLOW 0xffe0 |
Nikolas | 1:81d0d835991d | 103 | #define WHITE 0xffff |
Nikolas | 1:81d0d835991d | 104 | #define CYAN 0x07ff |
Nikolas | 1:81d0d835991d | 105 | #define BRIGHT_RED 0xf810 |
Nikolas | 1:81d0d835991d | 106 | #define GRAY1 0x8410 |
Nikolas | 1:81d0d835991d | 107 | #define GRAY2 0x4208 |
Nikolas | 1:81d0d835991d | 108 | */ |
Nikolas | 1:81d0d835991d | 109 | #define Navy 0x000F /* 0, 0, 128 */ |
Nikolas | 1:81d0d835991d | 110 | #define DarkGreen 0x03E0 /* 0, 128, 0 */ |
Nikolas | 1:81d0d835991d | 111 | #define DarkCyan 0x03EF /* 0, 128, 128 */ |
Nikolas | 1:81d0d835991d | 112 | #define Maroon 0x7800 /* 128, 0, 0 */ |
Nikolas | 1:81d0d835991d | 113 | #define Purple 0x780F /* 128, 0, 128 */ |
Nikolas | 1:81d0d835991d | 114 | #define Olive 0x7BE0 /* 128, 128, 0 */ |
Nikolas | 1:81d0d835991d | 115 | #define LightGrey 0xC618 /* 192, 192, 192 */ |
Nikolas | 1:81d0d835991d | 116 | #define DarkGrey 0x7BEF /* 128, 128, 128 */ |
Nikolas | 1:81d0d835991d | 117 | #define Magenta 0xF81F /* 255, 0, 255 */ |
Nikolas | 1:81d0d835991d | 118 | #define Orange 0xFD20 /* 255, 165, 0 */ |
Nikolas | 1:81d0d835991d | 119 | #define GreenYellow 0xAFE5 /* 173, 255, 47 */ |
Nikolas | 1:81d0d835991d | 120 | #define Pink 0xF81F |
Nikolas | 1:81d0d835991d | 121 | |
TFuchsbichler | 3:03c08a612220 | 122 | //Ticker initialisieren |
TFuchsbichler | 0:dd55ca105ef3 | 123 | Ticker Tick; |
TFuchsbichler | 0:dd55ca105ef3 | 124 | |
TFuchsbichler | 3:03c08a612220 | 125 | //Globale Variablen |
TFuchsbichler | 0:dd55ca105ef3 | 126 | float a; |
TFuchsbichler | 0:dd55ca105ef3 | 127 | int msek; |
TFuchsbichler | 0:dd55ca105ef3 | 128 | int sek; |
TFuchsbichler | 0:dd55ca105ef3 | 129 | int min; |
TFuchsbichler | 0:dd55ca105ef3 | 130 | int stund; |
TFuchsbichler | 3:03c08a612220 | 131 | int lsek; |
TFuchsbichler | 3:03c08a612220 | 132 | int lmin; |
TFuchsbichler | 3:03c08a612220 | 133 | int lstund; |
TFuchsbichler | 0:dd55ca105ef3 | 134 | bool mode; |
TFuchsbichler | 3:03c08a612220 | 135 | bool lhilf=false; |
TFuchsbichler | 0:dd55ca105ef3 | 136 | |
TFuchsbichler | 3:03c08a612220 | 137 | //Funktionsaufruf des Tickersinterrupts der Stoppuhr |
TFuchsbichler | 0:dd55ca105ef3 | 138 | void zaehl() |
TFuchsbichler | 0:dd55ca105ef3 | 139 | { |
TFuchsbichler | 0:dd55ca105ef3 | 140 | if(mode==true) { |
TFuchsbichler | 0:dd55ca105ef3 | 141 | msek++; |
TFuchsbichler | 3:03c08a612220 | 142 | //msek in sek |
TFuchsbichler | 0:dd55ca105ef3 | 143 | if(msek==100) { |
TFuchsbichler | 0:dd55ca105ef3 | 144 | sek++; |
TFuchsbichler | 0:dd55ca105ef3 | 145 | msek=0; |
TFuchsbichler | 0:dd55ca105ef3 | 146 | |
TFuchsbichler | 0:dd55ca105ef3 | 147 | } |
TFuchsbichler | 0:dd55ca105ef3 | 148 | |
TFuchsbichler | 3:03c08a612220 | 149 | //sek in min |
TFuchsbichler | 0:dd55ca105ef3 | 150 | if(sek==60) { |
TFuchsbichler | 0:dd55ca105ef3 | 151 | min++; |
TFuchsbichler | 0:dd55ca105ef3 | 152 | sek=0; |
TFuchsbichler | 0:dd55ca105ef3 | 153 | |
TFuchsbichler | 0:dd55ca105ef3 | 154 | } |
TFuchsbichler | 0:dd55ca105ef3 | 155 | |
TFuchsbichler | 3:03c08a612220 | 156 | //min in stund |
TFuchsbichler | 0:dd55ca105ef3 | 157 | if(min==60) { |
TFuchsbichler | 0:dd55ca105ef3 | 158 | stund++; |
TFuchsbichler | 0:dd55ca105ef3 | 159 | min=0; |
TFuchsbichler | 0:dd55ca105ef3 | 160 | } |
TFuchsbichler | 3:03c08a612220 | 161 | |
TFuchsbichler | 3:03c08a612220 | 162 | //stund reseten |
TFuchsbichler | 0:dd55ca105ef3 | 163 | if(stund==24) { |
TFuchsbichler | 0:dd55ca105ef3 | 164 | msek=0; |
TFuchsbichler | 0:dd55ca105ef3 | 165 | sek=0; |
TFuchsbichler | 0:dd55ca105ef3 | 166 | min=0; |
TFuchsbichler | 0:dd55ca105ef3 | 167 | stund=0; |
TFuchsbichler | 0:dd55ca105ef3 | 168 | } |
TFuchsbichler | 0:dd55ca105ef3 | 169 | |
TFuchsbichler | 0:dd55ca105ef3 | 170 | } |
TFuchsbichler | 0:dd55ca105ef3 | 171 | |
TFuchsbichler | 0:dd55ca105ef3 | 172 | } |
TFuchsbichler | 0:dd55ca105ef3 | 173 | |
TFuchsbichler | 3:03c08a612220 | 174 | //"Falsche" Zwischenzeit stoppen |
TFuchsbichler | 3:03c08a612220 | 175 | void lap() |
TFuchsbichler | 3:03c08a612220 | 176 | { |
TFuchsbichler | 3:03c08a612220 | 177 | |
TFuchsbichler | 3:03c08a612220 | 178 | tft.drawNumber(78,250,stund,2,1); |
TFuchsbichler | 3:03c08a612220 | 179 | tft.drawString(94, 250, ":"); |
TFuchsbichler | 3:03c08a612220 | 180 | tft.drawNumber(102,250,min,2,1); |
TFuchsbichler | 3:03c08a612220 | 181 | tft.drawString(118, 250, ":"); |
TFuchsbichler | 3:03c08a612220 | 182 | tft.drawNumber(126,250,sek,2,1); |
TFuchsbichler | 3:03c08a612220 | 183 | tft.drawString(142, 250, ":"); |
TFuchsbichler | 3:03c08a612220 | 184 | tft.drawNumber(150,250,msek,2,1); |
TFuchsbichler | 3:03c08a612220 | 185 | |
TFuchsbichler | 3:03c08a612220 | 186 | } |
TFuchsbichler | 3:03c08a612220 | 187 | |
TFuchsbichler | 3:03c08a612220 | 188 | //Stoppuhr reseten |
TFuchsbichler | 0:dd55ca105ef3 | 189 | void reset() |
TFuchsbichler | 0:dd55ca105ef3 | 190 | { |
TFuchsbichler | 0:dd55ca105ef3 | 191 | msek=0; |
TFuchsbichler | 0:dd55ca105ef3 | 192 | sek=0; |
TFuchsbichler | 0:dd55ca105ef3 | 193 | min=0; |
TFuchsbichler | 0:dd55ca105ef3 | 194 | stund=0; |
TFuchsbichler | 3:03c08a612220 | 195 | lap(); |
TFuchsbichler | 0:dd55ca105ef3 | 196 | } |
TFuchsbichler | 0:dd55ca105ef3 | 197 | |
TFuchsbichler | 3:03c08a612220 | 198 | //Startseite zeichnen |
TFuchsbichler | 2:e1b98fac05ed | 199 | void drawButtons() |
TFuchsbichler | 0:dd55ca105ef3 | 200 | { |
TFuchsbichler | 2:e1b98fac05ed | 201 | tft.clearScreen(BLACK); |
TFuchsbichler | 3:03c08a612220 | 202 | //Rectangles |
TFuchsbichler | 0:dd55ca105ef3 | 203 | tft.drawRectangle(25, 285, 74, 310,WHITE); |
TFuchsbichler | 0:dd55ca105ef3 | 204 | tft.drawRectangle(95, 285, 144, 310,WHITE); |
TFuchsbichler | 0:dd55ca105ef3 | 205 | tft.drawRectangle(165, 285,214, 310,WHITE); |
TFuchsbichler | 0:dd55ca105ef3 | 206 | tft.fillRectangle(26, 286, 73, 309, GREEN); |
TFuchsbichler | 0:dd55ca105ef3 | 207 | tft.fillRectangle(96, 286, 143, 309, RED); |
TFuchsbichler | 0:dd55ca105ef3 | 208 | //Text |
TFuchsbichler | 0:dd55ca105ef3 | 209 | tft.drawString(84, 30, "STOPWATCH"); |
Nikolas | 1:81d0d835991d | 210 | tft.setTextColor(GREEN, BLACK); |
TFuchsbichler | 0:dd55ca105ef3 | 211 | tft.drawString(30, 290, "START"); |
Nikolas | 1:81d0d835991d | 212 | tft.setTextColor(RED, BLACK); |
TFuchsbichler | 0:dd55ca105ef3 | 213 | tft.drawString(104, 290, "STOP"); |
Nikolas | 1:81d0d835991d | 214 | tft.setTextColor(BLACK, WHITE); |
TFuchsbichler | 0:dd55ca105ef3 | 215 | tft.drawString(170, 290, "RESET"); |
TFuchsbichler | 0:dd55ca105ef3 | 216 | touch.init(); |
TFuchsbichler | 2:e1b98fac05ed | 217 | |
TFuchsbichler | 2:e1b98fac05ed | 218 | tft.drawImage(208,0,32,32,zahnrad); |
TFuchsbichler | 2:e1b98fac05ed | 219 | |
TFuchsbichler | 2:e1b98fac05ed | 220 | |
TFuchsbichler | 2:e1b98fac05ed | 221 | } |
TFuchsbichler | 3:03c08a612220 | 222 | |
TFuchsbichler | 3:03c08a612220 | 223 | |
TFuchsbichler | 3:03c08a612220 | 224 | //Einstellungen der RTC(Real Time Clock) |
TFuchsbichler | 2:e1b98fac05ed | 225 | void RTC_SETUP() |
TFuchsbichler | 2:e1b98fac05ed | 226 | { |
TFuchsbichler | 2:e1b98fac05ed | 227 | tft.clearScreen(BLACK); |
TFuchsbichler | 2:e1b98fac05ed | 228 | |
TFuchsbichler | 3:03c08a612220 | 229 | lhilf=true; |
TFuchsbichler | 3:03c08a612220 | 230 | |
TFuchsbichler | 2:e1b98fac05ed | 231 | tft.drawImage(176,0,64,32,accept); |
TFuchsbichler | 3:03c08a612220 | 232 | |
TFuchsbichler | 3:03c08a612220 | 233 | tft.drawImage(20,80,32,32,arrow_up); |
TFuchsbichler | 3:03c08a612220 | 234 | tft.drawImage(104,80,32,32,arrow_up); |
TFuchsbichler | 3:03c08a612220 | 235 | tft.drawImage(188,80,32,32,arrow_up); |
TFuchsbichler | 3:03c08a612220 | 236 | |
TFuchsbichler | 3:03c08a612220 | 237 | tft.drawImage(20,140,32,32,arrow_down); |
TFuchsbichler | 3:03c08a612220 | 238 | tft.drawImage(104,140,32,32,arrow_down); |
TFuchsbichler | 3:03c08a612220 | 239 | tft.drawImage(188,140,32,32,arrow_down); |
TFuchsbichler | 3:03c08a612220 | 240 | |
TFuchsbichler | 2:e1b98fac05ed | 241 | tft.drawString(84, 30, "SETTINGS"); |
TFuchsbichler | 3:03c08a612220 | 242 | |
TFuchsbichler | 2:e1b98fac05ed | 243 | while(1) { |
Nikolas | 1:81d0d835991d | 244 | secondsSince1970 = time(NULL); |
TFuchsbichler | 3:03c08a612220 | 245 | |
TFuchsbichler | 3:03c08a612220 | 246 | tft.drawNumber(28, 118,lstund,2,1); |
TFuchsbichler | 3:03c08a612220 | 247 | tft.drawNumber(112, 118, lmin,2,1); |
TFuchsbichler | 3:03c08a612220 | 248 | tft.drawNumber(196, 118, lsek,2,1); |
TFuchsbichler | 3:03c08a612220 | 249 | |
TFuchsbichler | 3:03c08a612220 | 250 | if(lstund==9&&lmin==1&&lsek==1&&lhilf==true) |
TFuchsbichler | 3:03c08a612220 | 251 | { |
TFuchsbichler | 3:03c08a612220 | 252 | //cages |
TFuchsbichler | 3:03c08a612220 | 253 | tft.drawImage(0,200,60,60,cage); |
TFuchsbichler | 3:03c08a612220 | 254 | tft.drawImage(60,200,60,60,cage); |
TFuchsbichler | 3:03c08a612220 | 255 | tft.drawImage(120,200,60,60,cage); |
TFuchsbichler | 3:03c08a612220 | 256 | tft.drawImage(180,200,60,60,cage); |
TFuchsbichler | 3:03c08a612220 | 257 | |
TFuchsbichler | 3:03c08a612220 | 258 | tft.drawImage(0,260,60,60,cage); |
TFuchsbichler | 3:03c08a612220 | 259 | tft.drawImage(60,260,60,60,cage); |
TFuchsbichler | 3:03c08a612220 | 260 | tft.drawImage(120,260,60,60,cage); |
TFuchsbichler | 3:03c08a612220 | 261 | tft.drawImage(180,260,60,60,cage); |
TFuchsbichler | 3:03c08a612220 | 262 | |
TFuchsbichler | 3:03c08a612220 | 263 | wait(2); |
TFuchsbichler | 3:03c08a612220 | 264 | |
TFuchsbichler | 3:03c08a612220 | 265 | tft.fillRectangle(0,200,240,320,BLACK); |
TFuchsbichler | 3:03c08a612220 | 266 | lhilf=false; |
TFuchsbichler | 3:03c08a612220 | 267 | } |
TFuchsbichler | 3:03c08a612220 | 268 | |
TFuchsbichler | 0:dd55ca105ef3 | 269 | touch.readTouchData(x, y, down); |
TFuchsbichler | 2:e1b98fac05ed | 270 | if(down==true&&x>=208&&x<=240&&y>=0&&y<=32) { |
TFuchsbichler | 2:e1b98fac05ed | 271 | wait(0.25); |
TFuchsbichler | 2:e1b98fac05ed | 272 | drawButtons(); |
TFuchsbichler | 2:e1b98fac05ed | 273 | return; |
TFuchsbichler | 2:e1b98fac05ed | 274 | } |
TFuchsbichler | 2:e1b98fac05ed | 275 | |
TFuchsbichler | 3:03c08a612220 | 276 | //Stunden Konfiguration |
TFuchsbichler | 3:03c08a612220 | 277 | if(down==true&&x>=20&&x<=52&&y>=80&&y<=112) { |
TFuchsbichler | 3:03c08a612220 | 278 | lstund++; |
TFuchsbichler | 3:03c08a612220 | 279 | if(lstund>=24) |
TFuchsbichler | 3:03c08a612220 | 280 | lstund=0; |
TFuchsbichler | 3:03c08a612220 | 281 | wait(0.25); |
TFuchsbichler | 3:03c08a612220 | 282 | } |
TFuchsbichler | 3:03c08a612220 | 283 | if(down==true&&x>=20&&x<=52&&y>=140&&y<=172) { |
TFuchsbichler | 3:03c08a612220 | 284 | lstund--; |
TFuchsbichler | 3:03c08a612220 | 285 | if(lstund<0) |
TFuchsbichler | 3:03c08a612220 | 286 | lstund=23; |
TFuchsbichler | 3:03c08a612220 | 287 | wait(0.25); |
TFuchsbichler | 3:03c08a612220 | 288 | } |
TFuchsbichler | 3:03c08a612220 | 289 | |
TFuchsbichler | 3:03c08a612220 | 290 | |
TFuchsbichler | 3:03c08a612220 | 291 | //Minuten Konfiguration |
TFuchsbichler | 3:03c08a612220 | 292 | if(down==true&&x>=104&&x<=136&y>=80&&y<=112) { |
TFuchsbichler | 3:03c08a612220 | 293 | lmin++; |
TFuchsbichler | 3:03c08a612220 | 294 | if(lmin>=60) |
TFuchsbichler | 3:03c08a612220 | 295 | lmin=0; |
TFuchsbichler | 3:03c08a612220 | 296 | wait(0.25); |
TFuchsbichler | 3:03c08a612220 | 297 | } |
TFuchsbichler | 3:03c08a612220 | 298 | if(down==true&&x>=104&&x<=136&&y>=140&&y<=172) { |
TFuchsbichler | 3:03c08a612220 | 299 | lmin--; |
TFuchsbichler | 3:03c08a612220 | 300 | if(lmin<0) |
TFuchsbichler | 3:03c08a612220 | 301 | lmin=59; |
TFuchsbichler | 3:03c08a612220 | 302 | wait(0.25); |
TFuchsbichler | 3:03c08a612220 | 303 | } |
TFuchsbichler | 3:03c08a612220 | 304 | |
TFuchsbichler | 3:03c08a612220 | 305 | |
TFuchsbichler | 3:03c08a612220 | 306 | //Sekunden Konfiguration |
TFuchsbichler | 3:03c08a612220 | 307 | if(down==true&&x>=188&&x<=220&&y>=80&&y<=112) { |
TFuchsbichler | 3:03c08a612220 | 308 | lsek++; |
TFuchsbichler | 3:03c08a612220 | 309 | if(lsek>=60) |
TFuchsbichler | 3:03c08a612220 | 310 | lsek=0; |
TFuchsbichler | 3:03c08a612220 | 311 | wait(0.25); |
TFuchsbichler | 3:03c08a612220 | 312 | } |
TFuchsbichler | 3:03c08a612220 | 313 | |
TFuchsbichler | 3:03c08a612220 | 314 | if(down==true&&x>=188&&x<=220&&y>=140&&y<=172) { |
TFuchsbichler | 3:03c08a612220 | 315 | lsek--; |
TFuchsbichler | 3:03c08a612220 | 316 | if(lsek<0) |
TFuchsbichler | 3:03c08a612220 | 317 | lsek=59; |
TFuchsbichler | 3:03c08a612220 | 318 | wait(0.25); |
TFuchsbichler | 3:03c08a612220 | 319 | } |
TFuchsbichler | 2:e1b98fac05ed | 320 | if(down==true&&x>=176&&x<=208&&y>=0&&y<=32) { |
TFuchsbichler | 3:03c08a612220 | 321 | struct tm t; |
TFuchsbichler | 3:03c08a612220 | 322 | t.tm_sec = lsek; // 0-59 |
TFuchsbichler | 3:03c08a612220 | 323 | t.tm_min = lmin; // 0-59 |
TFuchsbichler | 3:03c08a612220 | 324 | t.tm_hour = lstund; // 0-23 |
TFuchsbichler | 3:03c08a612220 | 325 | t.tm_mday = 29; // 1-31 |
TFuchsbichler | 3:03c08a612220 | 326 | t.tm_mon = 1; // 0-11 |
TFuchsbichler | 3:03c08a612220 | 327 | t.tm_year = 116; // year since 1900 |
TFuchsbichler | 3:03c08a612220 | 328 | |
TFuchsbichler | 3:03c08a612220 | 329 | |
TFuchsbichler | 3:03c08a612220 | 330 | // convert to timestamp |
TFuchsbichler | 3:03c08a612220 | 331 | time_t secondsSince1970 = mktime(&t); |
TFuchsbichler | 3:03c08a612220 | 332 | |
TFuchsbichler | 3:03c08a612220 | 333 | // Set time and start RTC |
TFuchsbichler | 3:03c08a612220 | 334 | set_time(secondsSince1970); |
TFuchsbichler | 3:03c08a612220 | 335 | |
TFuchsbichler | 2:e1b98fac05ed | 336 | wait(0.25); |
TFuchsbichler | 2:e1b98fac05ed | 337 | drawButtons(); |
TFuchsbichler | 2:e1b98fac05ed | 338 | return; |
TFuchsbichler | 2:e1b98fac05ed | 339 | } |
TFuchsbichler | 2:e1b98fac05ed | 340 | |
TFuchsbichler | 2:e1b98fac05ed | 341 | |
TFuchsbichler | 2:e1b98fac05ed | 342 | } |
TFuchsbichler | 2:e1b98fac05ed | 343 | |
TFuchsbichler | 2:e1b98fac05ed | 344 | |
TFuchsbichler | 2:e1b98fac05ed | 345 | } |
TFuchsbichler | 2:e1b98fac05ed | 346 | /****************************************************************************** |
TFuchsbichler | 2:e1b98fac05ed | 347 | * Main |
TFuchsbichler | 2:e1b98fac05ed | 348 | *****************************************************************************/ |
TFuchsbichler | 2:e1b98fac05ed | 349 | |
TFuchsbichler | 2:e1b98fac05ed | 350 | int main() |
TFuchsbichler | 2:e1b98fac05ed | 351 | { |
TFuchsbichler | 3:03c08a612220 | 352 | |
TFuchsbichler | 2:e1b98fac05ed | 353 | |
TFuchsbichler | 2:e1b98fac05ed | 354 | struct tm t; |
TFuchsbichler | 2:e1b98fac05ed | 355 | t.tm_sec = 00; // 0-59 |
TFuchsbichler | 2:e1b98fac05ed | 356 | t.tm_min = 12; // 0-59 |
TFuchsbichler | 2:e1b98fac05ed | 357 | t.tm_hour = 10; // 0-23 |
TFuchsbichler | 3:03c08a612220 | 358 | t.tm_mday = 29; // 1-31 |
TFuchsbichler | 3:03c08a612220 | 359 | t.tm_mon = 1; // 0-11 |
TFuchsbichler | 3:03c08a612220 | 360 | t.tm_year = 116; // year since 1900 |
TFuchsbichler | 2:e1b98fac05ed | 361 | |
TFuchsbichler | 2:e1b98fac05ed | 362 | // convert to timestamp |
TFuchsbichler | 2:e1b98fac05ed | 363 | time_t secondsSince1970 = mktime(&t); |
TFuchsbichler | 2:e1b98fac05ed | 364 | |
TFuchsbichler | 2:e1b98fac05ed | 365 | // Set time and start RTC |
TFuchsbichler | 2:e1b98fac05ed | 366 | set_time(secondsSince1970); |
TFuchsbichler | 2:e1b98fac05ed | 367 | |
TFuchsbichler | 2:e1b98fac05ed | 368 | log("init tft \r\n"); |
TFuchsbichler | 2:e1b98fac05ed | 369 | mode=false; |
TFuchsbichler | 2:e1b98fac05ed | 370 | tft.init(); |
TFuchsbichler | 2:e1b98fac05ed | 371 | Tick.attach(&zaehl, 0.01); |
TFuchsbichler | 2:e1b98fac05ed | 372 | |
TFuchsbichler | 2:e1b98fac05ed | 373 | drawButtons(); |
TFuchsbichler | 2:e1b98fac05ed | 374 | |
TFuchsbichler | 2:e1b98fac05ed | 375 | while (1) { |
TFuchsbichler | 2:e1b98fac05ed | 376 | secondsSince1970 = time(NULL); |
TFuchsbichler | 2:e1b98fac05ed | 377 | strftime(timeString, 20, "%H:%M:%S", localtime(&secondsSince1970)); |
TFuchsbichler | 2:e1b98fac05ed | 378 | tft.drawString(90, 50, timeString); |
TFuchsbichler | 2:e1b98fac05ed | 379 | |
TFuchsbichler | 2:e1b98fac05ed | 380 | touch.readTouchData(x, y, down); |
TFuchsbichler | 3:03c08a612220 | 381 | |
TFuchsbichler | 2:e1b98fac05ed | 382 | if(down==true&&x>=208&&x<=240&&y>=0&&y<=32) |
TFuchsbichler | 3:03c08a612220 | 383 | { |
TFuchsbichler | 3:03c08a612220 | 384 | strftime(timeString, 20, "%H", localtime(&secondsSince1970)); |
TFuchsbichler | 3:03c08a612220 | 385 | lstund=atoi(timeString); |
TFuchsbichler | 3:03c08a612220 | 386 | //atoi: Wandelt string in int um |
TFuchsbichler | 3:03c08a612220 | 387 | |
TFuchsbichler | 3:03c08a612220 | 388 | strftime(timeString, 20, "%M", localtime(&secondsSince1970)); |
TFuchsbichler | 3:03c08a612220 | 389 | lmin=atoi(timeString); |
TFuchsbichler | 2:e1b98fac05ed | 390 | |
TFuchsbichler | 3:03c08a612220 | 391 | strftime(timeString, 20, "%S", localtime(&secondsSince1970)); |
TFuchsbichler | 3:03c08a612220 | 392 | lsek=atoi(timeString); |
TFuchsbichler | 3:03c08a612220 | 393 | RTC_SETUP(); |
TFuchsbichler | 3:03c08a612220 | 394 | } |
TFuchsbichler | 3:03c08a612220 | 395 | |
TFuchsbichler | 3:03c08a612220 | 396 | //Start Stoppuhr |
TFuchsbichler | 3:03c08a612220 | 397 | if(down==true&&x>=25&&x<=74&&y>=285&&y<=310) { |
TFuchsbichler | 3:03c08a612220 | 398 | if(mode==true) { |
TFuchsbichler | 3:03c08a612220 | 399 | lap(); |
TFuchsbichler | 3:03c08a612220 | 400 | } |
TFuchsbichler | 0:dd55ca105ef3 | 401 | mode=true; |
TFuchsbichler | 3:03c08a612220 | 402 | } |
TFuchsbichler | 3:03c08a612220 | 403 | //Stop Stoppuhr |
TFuchsbichler | 0:dd55ca105ef3 | 404 | if(down==true&&x>=95&&x<=144&&y>=285&&y<=310) |
TFuchsbichler | 0:dd55ca105ef3 | 405 | mode=false; |
TFuchsbichler | 3:03c08a612220 | 406 | //Reset Stoppuhr |
TFuchsbichler | 0:dd55ca105ef3 | 407 | if(down==true&&x>=165&&x<=214&&y>=285&&y<=310) |
TFuchsbichler | 0:dd55ca105ef3 | 408 | reset(); |
TFuchsbichler | 2:e1b98fac05ed | 409 | |
TFuchsbichler | 3:03c08a612220 | 410 | tft.drawNumber(78,230,stund,2,1); |
TFuchsbichler | 3:03c08a612220 | 411 | tft.drawString(94, 230, ":"); |
TFuchsbichler | 3:03c08a612220 | 412 | tft.drawNumber(102,230,min,2,1); |
TFuchsbichler | 3:03c08a612220 | 413 | tft.drawString(118, 230, ":"); |
TFuchsbichler | 3:03c08a612220 | 414 | tft.drawNumber(126,230,sek,2,1); |
TFuchsbichler | 3:03c08a612220 | 415 | tft.drawString(142, 230, ":"); |
TFuchsbichler | 3:03c08a612220 | 416 | tft.drawNumber(150,230,msek,2,1); |
TFuchsbichler | 0:dd55ca105ef3 | 417 | |
TFuchsbichler | 0:dd55ca105ef3 | 418 | down=false; |
TFuchsbichler | 0:dd55ca105ef3 | 419 | } |
TFuchsbichler | 0:dd55ca105ef3 | 420 | |
TFuchsbichler | 0:dd55ca105ef3 | 421 | } |