Simple integer calculator using FRDM-KL25Z and Adafruit 2.8" TFT with touch \\ "Dentaku" means "Desktop Calculator" in Japanese \\ On 5-Dec-2015, Support for FRDM-K64F, FRDM-K22F, NUCLEO-F411RE added.

Dependencies:   SPI_STMPE610 UniGraphic mbed vt100

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /** mbed oscilloscope my implementation of a oscillo scope
00002  * Copyright (c) 2014, 2015 Motoo Tanaka @ Design Methodology Lab
00003  *
00004  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00005  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00006  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00007  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00008  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00009  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00010  * THE SOFTWARE.
00011  */
00012 #include "mbed.h"
00013 #include <string.h>
00014 #include <ILI9341.h>
00015 //#include "Arial12x12.h"
00016 //#include "Arial24x23.h"
00017 #include "Arial28x28.h"
00018 //#include "Arial43x48_numb.h"
00019 #include "SPI_STMPE610.h"
00020 #include "vt100.h"
00021 #include "TFTMenu.h"
00022 #include "menu.h"
00023 #include "main.h"
00024 
00025 #if defined (TARGET_MAX32600MBED)
00026 vt100 tty(57600) ;
00027 #else
00028 vt100 tty ;
00029 #endif 
00030 
00031 DigitalOut tsc_cs(PIN_CS_TSC, 1) ;
00032 DigitalOut backlight(PIN_BL_TFT, 0) ;
00033 ILI9341 TFT(SPI_8, 10000000, 
00034     PIN_MOSI, PIN_MISO,  PIN_SCLK, 
00035     PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "Adafruit2.8") ;
00036 SPI_STMPE610 TSC(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ;
00037 TFTMenuItem *menu[NUM_MAX_MENU] ;
00038 int numMenu = 0 ;
00039 
00040 void initTFT(void)
00041 {
00042     //Configure the display driver
00043     TFT.BusEnable(true) ;
00044     TFT.FastWindow(true) ;
00045     TFT.background(Black);
00046     TFT.foreground(White);
00047     wait(0.01) ;
00048     TFT.cls();
00049     TFT.set_orientation(0) ;
00050     wait(0.1) ;
00051     TFT.BusEnable(false) ;
00052 }
00053 
00054 void hello()
00055 {
00056     printf("=== simple calculator ===\n\r") ;
00057     printf("built: %s\n\r",__DATE__) ;
00058 }
00059 
00060 void display(char *label)
00061 {
00062     char str[16] ;
00063     int dummy ;
00064     int x = 200 ;
00065     int y = 30 ;
00066     int font_width = 16 ;
00067     dummy = topValue ;
00068 
00069     TFT.BusEnable(true) ;
00070     TFT.fillrect(0, 0, 239, 80, Black) ;
00071     wait(0.1) ;
00072     TFT.foreground(White) ;
00073     TFT.background(Black) ;
00074     wait(0.01) ;
00075     TFT.set_font((unsigned char *)Arial28x28) ;
00076     wait(0.1) ;
00077     
00078     if ((label != 0)&&(*label != 0)) {
00079         strcpy(str, label) ;
00080     } else {
00081         sprintf(str, "%d", dummy) ;
00082     }
00083     x = 228 - (strlen(str) * font_width) ;
00084     TFT.locate(x, y) ;
00085     TFT.printf(str) ;
00086     TFT.BusEnable(false) ;
00087 }
00088 
00089 int main() 
00090 {
00091     int touched ;
00092     uint16_t x, y ;
00093     bool result ;
00094     tsc_cs = 1 ; 
00095 
00096     backlight = 0 ;
00097     initTFT() ;
00098     initMenu() ;    
00099     drawMenu() ;
00100     backlight = 1 ;
00101     hello() ;
00102     
00103     display() ;
00104     
00105     while(1) {
00106 //       tsc_cs = 0 ;
00107         touched = TSC.getPoint(&x, &y) ;
00108 //        tsc_cs = 1 ;
00109 //        if (touched && ((x != 0)||(y != 0))) { // TSC sometimes returns (0,0)
00110         if ((x != 0)||(y !=0)) { // FRDM-KL46Z fails to return touched somehow
00111             result = doMenu(x, y) ;
00112         }
00113         wait(0.01) ;
00114     }
00115 }