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:
Sun Aug 02 14:00:59 2015 +0000
Revision:
0:659a74b77279
Child:
2:ddf8d8fffb4f
commit before publish;

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 0:659a74b77279 25 vt100 tty ;
Rhyme 0:659a74b77279 26 DigitalOut tsc_cs(PIN_CS_TSC, 1) ;
Rhyme 0:659a74b77279 27 DigitalOut backlight(PIN_BL_TFT, 0) ;
Rhyme 0:659a74b77279 28 ILI9341 TFT(SPI_8, 10000000,
Rhyme 0:659a74b77279 29 PIN_MOSI, PIN_MISO, PIN_SCLK,
Rhyme 0:659a74b77279 30 PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "Adafruit2.8") ;
Rhyme 0:659a74b77279 31 SPI_STMPE610 TSC(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ;
Rhyme 0:659a74b77279 32 TFTMenuItem *menu[NUM_MAX_MENU] ;
Rhyme 0:659a74b77279 33 int numMenu = 0 ;
Rhyme 0:659a74b77279 34
Rhyme 0:659a74b77279 35 void initTFT(void)
Rhyme 0:659a74b77279 36 {
Rhyme 0:659a74b77279 37 //Configure the display driver
Rhyme 0:659a74b77279 38 TFT.BusEnable(true) ;
Rhyme 0:659a74b77279 39 TFT.FastWindow(true) ;
Rhyme 0:659a74b77279 40 TFT.background(Black);
Rhyme 0:659a74b77279 41 TFT.foreground(White);
Rhyme 0:659a74b77279 42 wait(0.01) ;
Rhyme 0:659a74b77279 43 TFT.cls();
Rhyme 0:659a74b77279 44 TFT.set_orientation(0) ;
Rhyme 0:659a74b77279 45 wait(0.1) ;
Rhyme 0:659a74b77279 46 TFT.BusEnable(false) ;
Rhyme 0:659a74b77279 47 }
Rhyme 0:659a74b77279 48
Rhyme 0:659a74b77279 49 void hello()
Rhyme 0:659a74b77279 50 {
Rhyme 0:659a74b77279 51 printf("=== simple calculator ===\n\r") ;
Rhyme 0:659a74b77279 52 printf("built: %s\n\r",__DATE__) ;
Rhyme 0:659a74b77279 53 }
Rhyme 0:659a74b77279 54
Rhyme 0:659a74b77279 55 void display(char *label)
Rhyme 0:659a74b77279 56 {
Rhyme 0:659a74b77279 57 char str[16] ;
Rhyme 0:659a74b77279 58 int dummy ;
Rhyme 0:659a74b77279 59 int x = 200 ;
Rhyme 0:659a74b77279 60 int y = 30 ;
Rhyme 0:659a74b77279 61 int font_width = 16 ;
Rhyme 0:659a74b77279 62 dummy = topValue ;
Rhyme 0:659a74b77279 63
Rhyme 0:659a74b77279 64 TFT.BusEnable(true) ;
Rhyme 0:659a74b77279 65 TFT.fillrect(0, 0, 239, 80, Black) ;
Rhyme 0:659a74b77279 66 wait(0.1) ;
Rhyme 0:659a74b77279 67 TFT.foreground(White) ;
Rhyme 0:659a74b77279 68 TFT.background(Black) ;
Rhyme 0:659a74b77279 69 wait(0.01) ;
Rhyme 0:659a74b77279 70 TFT.set_font((unsigned char *)Arial28x28) ;
Rhyme 0:659a74b77279 71 wait(0.1) ;
Rhyme 0:659a74b77279 72
Rhyme 0:659a74b77279 73 if ((label != 0)&&(*label != 0)) {
Rhyme 0:659a74b77279 74 strcpy(str, label) ;
Rhyme 0:659a74b77279 75 } else {
Rhyme 0:659a74b77279 76 sprintf(str, "%d", dummy) ;
Rhyme 0:659a74b77279 77 }
Rhyme 0:659a74b77279 78 x = 228 - (strlen(str) * font_width) ;
Rhyme 0:659a74b77279 79 TFT.locate(x, y) ;
Rhyme 0:659a74b77279 80 TFT.printf(str) ;
Rhyme 0:659a74b77279 81 TFT.BusEnable(false) ;
Rhyme 0:659a74b77279 82 }
Rhyme 0:659a74b77279 83
Rhyme 0:659a74b77279 84 int main()
Rhyme 0:659a74b77279 85 {
Rhyme 0:659a74b77279 86 int touched ;
Rhyme 0:659a74b77279 87 uint16_t x, y ;
Rhyme 0:659a74b77279 88 bool result ;
Rhyme 0:659a74b77279 89 tsc_cs = 1 ;
Rhyme 0:659a74b77279 90
Rhyme 0:659a74b77279 91 backlight = 0 ;
Rhyme 0:659a74b77279 92 initTFT() ;
Rhyme 0:659a74b77279 93 initMenu() ;
Rhyme 0:659a74b77279 94 drawMenu() ;
Rhyme 0:659a74b77279 95 backlight = 1 ;
Rhyme 0:659a74b77279 96 hello() ;
Rhyme 0:659a74b77279 97
Rhyme 0:659a74b77279 98 display() ;
Rhyme 0:659a74b77279 99
Rhyme 0:659a74b77279 100 while(1) {
Rhyme 0:659a74b77279 101 // tsc_cs = 0 ;
Rhyme 0:659a74b77279 102 touched = TSC.getPoint(&x, &y) ;
Rhyme 0:659a74b77279 103 // tsc_cs = 1 ;
Rhyme 0:659a74b77279 104 // if (touched && ((x != 0)||(y != 0))) { // TSC sometimes returns (0,0)
Rhyme 0:659a74b77279 105 if ((x != 0)||(y !=0)) { // FRDM-KL46Z fails to return touched somehow
Rhyme 0:659a74b77279 106 result = doMenu(x, y) ;
Rhyme 0:659a74b77279 107 }
Rhyme 0:659a74b77279 108 wait(0.1) ;
Rhyme 0:659a74b77279 109 }
Rhyme 0:659a74b77279 110 }