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

Yet another simple desktop calculator program, only for integer.
As usual I used FRDM-KL25Z, Adafruit 2.8" TFT with touch and UniGraphic library.
Now works with FRDM-K64F, FRDM-K22F, and NUCLEO-F411RE.

整数計算のみの簡単な電卓プログラムです。
例によって、FRDM-KL25Z, Adafruit 2.8" TFT with touch, そして UniGraphic を使用しています。
FRDM-K64F, FRDM-K22F, NUCLEO-F411RE でも動くようになりました。

/media/uploads/Rhyme/img_1194.jpg

Committer:
Rhyme
Date:
Tue Apr 11 06:06:25 2017 +0000
Revision:
4:d4c937bcc469
Parent:
3:998ba6618f38
Support of MAX32600 added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:659a74b77279 1 /** mbed oscilloscope my implementation of a oscillo scope
Rhyme 0:659a74b77279 2 * Copyright (c) 2014, 2015 Motoo Tanaka @ Design Methodology Lab
Rhyme 0:659a74b77279 3 *
Rhyme 0:659a74b77279 4 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Rhyme 0:659a74b77279 5 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Rhyme 0:659a74b77279 6 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Rhyme 0:659a74b77279 7 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Rhyme 0:659a74b77279 8 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Rhyme 0:659a74b77279 9 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Rhyme 0:659a74b77279 10 * THE SOFTWARE.
Rhyme 0:659a74b77279 11 */
Rhyme 0:659a74b77279 12 #include "mbed.h"
Rhyme 0:659a74b77279 13 #include <string.h>
Rhyme 0:659a74b77279 14 #include <ILI9341.h>
Rhyme 0:659a74b77279 15 //#include "Arial12x12.h"
Rhyme 0:659a74b77279 16 //#include "Arial24x23.h"
Rhyme 0:659a74b77279 17 #include "Arial28x28.h"
Rhyme 0:659a74b77279 18 //#include "Arial43x48_numb.h"
Rhyme 0:659a74b77279 19 #include "SPI_STMPE610.h"
Rhyme 0:659a74b77279 20 #include "vt100.h"
Rhyme 0:659a74b77279 21 #include "TFTMenu.h"
Rhyme 0:659a74b77279 22 #include "menu.h"
Rhyme 0:659a74b77279 23 #include "main.h"
Rhyme 0:659a74b77279 24
Rhyme 3:998ba6618f38 25 #if defined (TARGET_MAX32600MBED)
Rhyme 3:998ba6618f38 26 vt100 tty(57600) ;
Rhyme 3:998ba6618f38 27 #else
Rhyme 0:659a74b77279 28 vt100 tty ;
Rhyme 3:998ba6618f38 29 #endif
Rhyme 3:998ba6618f38 30
Rhyme 0:659a74b77279 31 DigitalOut tsc_cs(PIN_CS_TSC, 1) ;
Rhyme 0:659a74b77279 32 DigitalOut backlight(PIN_BL_TFT, 0) ;
Rhyme 0:659a74b77279 33 ILI9341 TFT(SPI_8, 10000000,
Rhyme 0:659a74b77279 34 PIN_MOSI, PIN_MISO, PIN_SCLK,
Rhyme 0:659a74b77279 35 PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "Adafruit2.8") ;
Rhyme 0:659a74b77279 36 SPI_STMPE610 TSC(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ;
Rhyme 0:659a74b77279 37 TFTMenuItem *menu[NUM_MAX_MENU] ;
Rhyme 0:659a74b77279 38 int numMenu = 0 ;
Rhyme 0:659a74b77279 39
Rhyme 0:659a74b77279 40 void initTFT(void)
Rhyme 0:659a74b77279 41 {
Rhyme 0:659a74b77279 42 //Configure the display driver
Rhyme 0:659a74b77279 43 TFT.BusEnable(true) ;
Rhyme 0:659a74b77279 44 TFT.FastWindow(true) ;
Rhyme 0:659a74b77279 45 TFT.background(Black);
Rhyme 0:659a74b77279 46 TFT.foreground(White);
Rhyme 0:659a74b77279 47 wait(0.01) ;
Rhyme 0:659a74b77279 48 TFT.cls();
Rhyme 0:659a74b77279 49 TFT.set_orientation(0) ;
Rhyme 0:659a74b77279 50 wait(0.1) ;
Rhyme 0:659a74b77279 51 TFT.BusEnable(false) ;
Rhyme 0:659a74b77279 52 }
Rhyme 0:659a74b77279 53
Rhyme 0:659a74b77279 54 void hello()
Rhyme 0:659a74b77279 55 {
Rhyme 0:659a74b77279 56 printf("=== simple calculator ===\n\r") ;
Rhyme 0:659a74b77279 57 printf("built: %s\n\r",__DATE__) ;
Rhyme 0:659a74b77279 58 }
Rhyme 0:659a74b77279 59
Rhyme 0:659a74b77279 60 void display(char *label)
Rhyme 0:659a74b77279 61 {
Rhyme 0:659a74b77279 62 char str[16] ;
Rhyme 0:659a74b77279 63 int dummy ;
Rhyme 0:659a74b77279 64 int x = 200 ;
Rhyme 0:659a74b77279 65 int y = 30 ;
Rhyme 0:659a74b77279 66 int font_width = 16 ;
Rhyme 0:659a74b77279 67 dummy = topValue ;
Rhyme 0:659a74b77279 68
Rhyme 0:659a74b77279 69 TFT.BusEnable(true) ;
Rhyme 0:659a74b77279 70 TFT.fillrect(0, 0, 239, 80, Black) ;
Rhyme 0:659a74b77279 71 wait(0.1) ;
Rhyme 0:659a74b77279 72 TFT.foreground(White) ;
Rhyme 0:659a74b77279 73 TFT.background(Black) ;
Rhyme 0:659a74b77279 74 wait(0.01) ;
Rhyme 0:659a74b77279 75 TFT.set_font((unsigned char *)Arial28x28) ;
Rhyme 0:659a74b77279 76 wait(0.1) ;
Rhyme 0:659a74b77279 77
Rhyme 0:659a74b77279 78 if ((label != 0)&&(*label != 0)) {
Rhyme 0:659a74b77279 79 strcpy(str, label) ;
Rhyme 0:659a74b77279 80 } else {
Rhyme 0:659a74b77279 81 sprintf(str, "%d", dummy) ;
Rhyme 0:659a74b77279 82 }
Rhyme 0:659a74b77279 83 x = 228 - (strlen(str) * font_width) ;
Rhyme 0:659a74b77279 84 TFT.locate(x, y) ;
Rhyme 0:659a74b77279 85 TFT.printf(str) ;
Rhyme 0:659a74b77279 86 TFT.BusEnable(false) ;
Rhyme 0:659a74b77279 87 }
Rhyme 0:659a74b77279 88
Rhyme 0:659a74b77279 89 int main()
Rhyme 0:659a74b77279 90 {
Rhyme 0:659a74b77279 91 int touched ;
Rhyme 0:659a74b77279 92 uint16_t x, y ;
Rhyme 0:659a74b77279 93 bool result ;
Rhyme 0:659a74b77279 94 tsc_cs = 1 ;
Rhyme 0:659a74b77279 95
Rhyme 0:659a74b77279 96 backlight = 0 ;
Rhyme 0:659a74b77279 97 initTFT() ;
Rhyme 0:659a74b77279 98 initMenu() ;
Rhyme 0:659a74b77279 99 drawMenu() ;
Rhyme 0:659a74b77279 100 backlight = 1 ;
Rhyme 0:659a74b77279 101 hello() ;
Rhyme 0:659a74b77279 102
Rhyme 0:659a74b77279 103 display() ;
Rhyme 0:659a74b77279 104
Rhyme 0:659a74b77279 105 while(1) {
Rhyme 0:659a74b77279 106 // tsc_cs = 0 ;
Rhyme 0:659a74b77279 107 touched = TSC.getPoint(&x, &y) ;
Rhyme 0:659a74b77279 108 // tsc_cs = 1 ;
Rhyme 0:659a74b77279 109 // if (touched && ((x != 0)||(y != 0))) { // TSC sometimes returns (0,0)
Rhyme 0:659a74b77279 110 if ((x != 0)||(y !=0)) { // FRDM-KL46Z fails to return touched somehow
Rhyme 0:659a74b77279 111 result = doMenu(x, y) ;
Rhyme 0:659a74b77279 112 }
Rhyme 2:ddf8d8fffb4f 113 wait(0.01) ;
Rhyme 0:659a74b77279 114 }
Rhyme 0:659a74b77279 115 }