![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
cbcx
Dependencies: DmTftLibrary mbed
Fork of LCD_Proj by
main.cpp
- Committer:
- TFuchsbichler
- Date:
- 2015-12-21
- Revision:
- 2:e1b98fac05ed
- Parent:
- 1:81d0d835991d
- Child:
- 3:03c08a612220
File content as of revision 2:e1b98fac05ed:
/********************************************************************************************** Copyright (c) 2014 DisplayModule. All rights reserved. Redistribution and use of this source code, part of this source code or any compiled binary based on this source code is permitted as long as the above copyright notice and following disclaimer is retained. DISCLAIMER: THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. ********************************************************************************************/ /****************************************************************************** * Tested on NUCLEO-F401RE, LPCXpresso11U68, LPCXpresso824-MAX platform. *****************************************************************************/ #include "mbed.h" #include "bild.h" #include "DmTftHX8353C.h" #include "DmTftS6D0164.h" #include "DmTftIli9325.h" #include "DmTftIli9341.h" #include "DmTftSsd2119.h" #include "DmTftRa8875.h" #include "DmTouch.h" #include "DmTpFt6x06.h" /****************************************************************************** * Typedefs and defines *****************************************************************************/ /* Note that there are restrictions on which platforms that can use printf in combinations with the DmTftLibrary. Some platforms (e.g. LPC1549 LPCXpresso) use the same pins for USBRX/USBTX and display control. Printing will cause the display to not work. Read more about this on the display's notebook page. */ //#define log(...) printf(__VA_ARGS__) #define log(...) #if 1 /* Displays without adapter */ #define DM_PIN_SPI_MOSI p5 #define DM_PIN_SPI_MISO p6 #define DM_PIN_SPI_SCLK p7 #define DM_PIN_CS_TOUCH p8 #define DM_PIN_CS_TFT p21 #define DM_PIN_CS_SDCARD p14 // 23 #define DM_PIN_CS_FLASH p10 // 24 #else /* Displays with adapter */ #define DM_PIN_SPI_MOSI p5 #define DM_PIN_SPI_MISO p6 #define DM_PIN_SPI_SCLK p7 #define DM_PIN_CS_TOUCH p8 #define DM_PIN_CS_TFT p21 #define DM_PIN_CS_SDCARD p14 // 13 #endif /****************************************************************************** * Local variables *****************************************************************************/ /********* TFT DISPLAY INIT *********/ 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*/ /********* TOUCH PANEL INIT *********/ DmTouch touch(DmTouch::DM_TFT28_105, p5, p6, p7); DigitalInOut csTouch(DM_PIN_CS_TOUCH, PIN_OUTPUT, PullUp, 1); DigitalInOut csDisplay(DM_PIN_CS_TFT, PIN_OUTPUT, PullUp, 1); DigitalInOut csSDCard(DM_PIN_CS_SDCARD, PIN_OUTPUT, PullUp, 1); #ifdef DM_PIN_CS_FLASH DigitalInOut csFlash(DM_PIN_CS_FLASH, PIN_OUTPUT, PullUp, 1); #endif PwmOut pwmRTC(p23); // RTC test PWM /****************************************************************************** * Global variables *****************************************************************************/ uint16_t x = 0; uint16_t y = 0; uint16_t w = tft.width(); uint16_t h = tft.height(); bool down=false; time_t secondsSince1970; char timeString[20]; /****************************************************************************** * Local functions *****************************************************************************/ /* #define RED 0xf800 #define GREEN 0x07e0 #define BLUE 0x001f #define BLACK 0x0000 #define YELLOW 0xffe0 #define WHITE 0xffff #define CYAN 0x07ff #define BRIGHT_RED 0xf810 #define GRAY1 0x8410 #define GRAY2 0x4208 */ #define Navy 0x000F /* 0, 0, 128 */ #define DarkGreen 0x03E0 /* 0, 128, 0 */ #define DarkCyan 0x03EF /* 0, 128, 128 */ #define Maroon 0x7800 /* 128, 0, 0 */ #define Purple 0x780F /* 128, 0, 128 */ #define Olive 0x7BE0 /* 128, 128, 0 */ #define LightGrey 0xC618 /* 192, 192, 192 */ #define DarkGrey 0x7BEF /* 128, 128, 128 */ #define Magenta 0xF81F /* 255, 0, 255 */ #define Orange 0xFD20 /* 255, 165, 0 */ #define GreenYellow 0xAFE5 /* 173, 255, 47 */ #define Pink 0xF81F Ticker Tick; float a; int msek; int sek; int min; int stund; bool mode; void zaehl() { if(mode==true) { msek++; if(msek==100) { sek++; msek=0; } if(sek==60) { min++; sek=0; } if(min==60) { stund++; min=0; } if(stund==24) { msek=0; sek=0; min=0; stund=0; } } } void reset() { msek=0; sek=0; min=0; stund=0; } void drawButtons() { tft.clearScreen(BLACK); //Rectangles tft.drawRectangle(25, 285, 74, 310,WHITE); tft.drawRectangle(95, 285, 144, 310,WHITE); tft.drawRectangle(165, 285,214, 310,WHITE); tft.fillRectangle(26, 286, 73, 309, GREEN); tft.fillRectangle(96, 286, 143, 309, RED); //Text tft.drawString(84, 30, "STOPWATCH"); tft.setTextColor(GREEN, BLACK); tft.drawString(30, 290, "START"); tft.setTextColor(RED, BLACK); tft.drawString(104, 290, "STOP"); tft.setTextColor(BLACK, WHITE); tft.drawString(170, 290, "RESET"); touch.init(); tft.drawImage(208,0,32,32,zahnrad); } void RTC_SETUP() { tft.clearScreen(BLACK); tft.drawImage(176,0,64,32,accept); tft.drawString(84, 30, "SETTINGS"); while(1) { secondsSince1970 = time(NULL); strftime(timeString, 20, "%H:%M:%S", localtime(&secondsSince1970)); tft.drawString(50, 50, timeString); touch.readTouchData(x, y, down); if(down==true&&x>=208&&x<=240&&y>=0&&y<=32) { wait(0.25); drawButtons(); return; } if(down==true&&x>=176&&x<=208&&y>=0&&y<=32) { wait(0.25); drawButtons(); return; } } } /****************************************************************************** * Main *****************************************************************************/ 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 // convert to timestamp time_t secondsSince1970 = mktime(&t); // Set time and start RTC set_time(secondsSince1970); log("init tft \r\n"); mode=false; tft.init(); Tick.attach(&zaehl, 0.01); drawButtons(); while (1) { secondsSince1970 = time(NULL); strftime(timeString, 20, "%H:%M:%S", localtime(&secondsSince1970)); tft.drawString(90, 50, timeString); touch.readTouchData(x, y, down); if(down==true&&x>=208&&x<=240&&y>=0&&y<=32) RTC_SETUP(); if(down==true&&x>=25&&x<=74&&y>=285&&y<=310) mode=true; if(down==true&&x>=95&&x<=144&&y>=285&&y<=310) mode=false; 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); down=false; } }