Adafruit TFT 2.8" test program for FRDM-K64F Note: J11 must be cut to make TSC work, but to download the program it must be reconnected, use pin-header and jumper.

Dependencies:   MMA8451Q SPI_STMPE610 SPI_TFT_ILI9341 TFT_fonts mbed

This program was to test Adafruit 2.8" TFT with touch with FRDM-K64F. After download the binary to the FRDM-K64F and push the reset button , a simple welcome message will be displayed.

このプログラムは私が秋月で購入した Adafruit 2.8" TFT http://akizukidenshi.com/catalog/g/gM-07747/ をFRDM-K64F で試すために書いたものです。 ダウンロード後にFRDM-K64Fのリセットスイッチを押すと 最初の画面が表示されます。

/media/uploads/Rhyme/img_0979_s.jpg

If you push and keep the right side of the screen, the screen will advance to the page2, which is a simple graph sample.

ここで画面の右側をしばらく押していると、次のページに移行します。 このページでは、簡単なグラフを表示する例を描画しています。

/media/uploads/Rhyme/img_0980_s.jpg

And if you do the same again, the program advances to the page3, which is a data display page of MMA8451Q accelerometer mounted on the FRDM-K64F. Note: Actually FRDM-K64F has FXOS8700CQ Acc + Mag, but it can emulate MMA8451Q.

さらに画面の右側をしばらく押していると、次のページに移行します。 ここでは、FRDM-K64Fに搭載されている MMA8451Q という3軸の 加速度センサの値を表示しています。 ※ 実はFRDM-K64F に搭載されているものは FXOS8700CQ というセンサなのですが、MMA8451Qのフリもしてくれるので、それを利用しています。

/media/uploads/Rhyme/img_0981_s.jpg

And this is the last page of this program, so far, so if you try to advance page, it will return to the first page. Note: Because of some bug, sometimes the clear screen fails and drawing of the page is screwed, but if you advance page or push reset button, usually it will return to normal picture.

このページが最後のページになっているので、さらにページ送りをすると 最初のページに戻ります。 ※ プログラム(もしくはライブラリ)のどこかに虫がいるようで ときどき画面消去に失敗して、複数の画面が重ね描きされたりします、 ページ送りをするか、リセットボタンを押すと通常状態に復帰できます。(^ ^;

Note: Probably some noticed that push and keep left side move the screen to the previous page. ※ 画面の左側を押し続けると、前のページ戻ることに  気づかれたかたもおいでかと思います。

/media/uploads/Rhyme/img_0982_s.jpg

BTW, I encountered a nasty problem with this setup, since OSBDM and TSC shares the same pin, you must cut the jumper at J11 to make TSC work, but you must reconnect it to make downloading work. At first I put the jumper pin on the top of the FRDM-K64F, but with this I had to remove the TFT everytime re-loading the program, which made me pretty unhappy, so I asked my friend to put a L-type jumper on the bottom of the board, so that the TFT panel can stay.

ところで、このセットアップの場合、OSBDMとTSCがピンを共用しているために、TSCを使えるようにするためには、J11のジャンパパターンを切る必要がありました。しかしプログラムをダウンロードするためには再度J11をショートする必要が出てきます。 最初、ジャンパピンを基板の上側につけたのですが、そうするとプログラムの度にTFTを外す必要が出てきます。耐えられなくなって友人にL型のジャンパピンを基板の裏側につけてもらうことで解決を見ました。

3-Jun-2015 With the newest FRDM-K64F TSC stopped working.!
After spending a few days, finally I found that the D8 pin which originally was PTA0 is now PTC12 !!
So for those with FRDM-K64 board rev E or later
The good news is that you don't have to cut the J11 anymore
The bad news is change pin definition for PIN_CS_TSC from PTA0 to PTC12.

For FRDM-K64F rev.E or later

#define PIN_CS_TSC   PTC12

2015年6月3日 最近のFRDM-K64Fでタッチセンサが効かないことがわかりました!
数日戦ったところ、D8に接続されているピンが PTA0 から PTC12 に変わっていることがわかりました!!
もしお持ちのFRDM-K64Fの基板リビジョンが E 以降であれば
良い報せとしては、もう J11 を切ってジャンパを付ける必要がなくなりました。
悪い報せとしては、コード内で TSC CS の定義を PTA0 から PTC12 に変更してください。

For FRDM-K64F rev.E or later

#define PIN_CS_TSC   PTC12
Committer:
Rhyme
Date:
Sun Nov 09 06:55:44 2014 +0000
Revision:
0:227c21cd26be
Child:
1:5ea1dc8f875f
Commit for publish;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:227c21cd26be 1 /*
Rhyme 0:227c21cd26be 2 main.cpp
Rhyme 0:227c21cd26be 3 2014 Copyright (c) Seeed Technology Inc. All right reserved.
Rhyme 0:227c21cd26be 4
Rhyme 0:227c21cd26be 5 Author:lawliet zou(lawliet.zou@gmail.com)
Rhyme 0:227c21cd26be 6 2014-02-17
Rhyme 0:227c21cd26be 7
Rhyme 0:227c21cd26be 8 This library is free software; you can redistribute it and/or
Rhyme 0:227c21cd26be 9 modify it under the terms of the GNU Lesser General Public
Rhyme 0:227c21cd26be 10 License as published by the Free Software Foundation; either
Rhyme 0:227c21cd26be 11 version 2.1 of the License, or (at your option) any later version.
Rhyme 0:227c21cd26be 12
Rhyme 0:227c21cd26be 13 This library is distributed in the hope that it will be useful,
Rhyme 0:227c21cd26be 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
Rhyme 0:227c21cd26be 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Rhyme 0:227c21cd26be 16 Lesser General Public License for more details.
Rhyme 0:227c21cd26be 17
Rhyme 0:227c21cd26be 18 You should have received a copy of the GNU Lesser General Public
Rhyme 0:227c21cd26be 19 License along with this library; if not, write to the Free Software
Rhyme 0:227c21cd26be 20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Rhyme 0:227c21cd26be 21 */
Rhyme 0:227c21cd26be 22
Rhyme 0:227c21cd26be 23 #include "mbed.h"
Rhyme 0:227c21cd26be 24 #include "MMA8451Q.h"
Rhyme 0:227c21cd26be 25 #include <math.h>
Rhyme 0:227c21cd26be 26 #include "SPI_TFT_ILI9341.h"
Rhyme 0:227c21cd26be 27 #include "SPI_STMPE610.h"
Rhyme 0:227c21cd26be 28 #include "Arial12x12.h"
Rhyme 0:227c21cd26be 29 #include "Arial24x23.h"
Rhyme 0:227c21cd26be 30 #include "Arial28x28.h"
Rhyme 0:227c21cd26be 31 #include "font_big.h"
Rhyme 0:227c21cd26be 32
Rhyme 0:227c21cd26be 33 #if 0
Rhyme 0:227c21cd26be 34 /*
Rhyme 0:227c21cd26be 35 // For FRDM-KL25Z
Rhyme 0:227c21cd26be 36 #define PIN_XP PTB3
Rhyme 0:227c21cd26be 37 #define PIN_XM PTB1
Rhyme 0:227c21cd26be 38 #define PIN_YP PTB2
Rhyme 0:227c21cd26be 39 #define PIN_YM PTB0
Rhyme 0:227c21cd26be 40 #define PIN_MOSI PTD2
Rhyme 0:227c21cd26be 41 #define PIN_MISO PTD3
Rhyme 0:227c21cd26be 42 #define PIN_SCLK PTD1
Rhyme 0:227c21cd26be 43 #define PIN_CS_TFT PTD0
Rhyme 0:227c21cd26be 44 #define PIN_DC_TFT PTD5
Rhyme 0:227c21cd26be 45 #define PIN_BL_TFT PTC9
Rhyme 0:227c21cd26be 46 #define PIN_CS_SD PTA4
Rhyme 0:227c21cd26be 47 #define PIN_CS_TSC PTA13
Rhyme 0:227c21cd26be 48 #define PIN_TSC_INTR PTC9
Rhyme 0:227c21cd26be 49 #define PIN_BACKLIGHT PTA12
Rhyme 0:227c21cd26be 50 */
Rhyme 0:227c21cd26be 51 #endif
Rhyme 0:227c21cd26be 52
Rhyme 0:227c21cd26be 53 #if 1
Rhyme 0:227c21cd26be 54 // For FRDM-K64F
Rhyme 0:227c21cd26be 55 #define PIN_XP PTB11
Rhyme 0:227c21cd26be 56 #define PIN_XM PTB3
Rhyme 0:227c21cd26be 57 #define PIN_YP PTB10
Rhyme 0:227c21cd26be 58 #define PIN_YM PTB2
Rhyme 0:227c21cd26be 59 #define PIN_MOSI PTD2
Rhyme 0:227c21cd26be 60 #define PIN_MISO PTD3
Rhyme 0:227c21cd26be 61 #define PIN_SCLK PTD1
Rhyme 0:227c21cd26be 62 #define PIN_CS_TFT PTD0
Rhyme 0:227c21cd26be 63 #define PIN_DC_TFT PTC4
Rhyme 0:227c21cd26be 64 #define PIN_BL_TFT PTC3
Rhyme 0:227c21cd26be 65 #define PIN_CS_SD PTB23
Rhyme 0:227c21cd26be 66 #define PIN_CS_TSC PTA0
Rhyme 0:227c21cd26be 67 #define PIN_TSC_INTR PTC3
Rhyme 0:227c21cd26be 68 #define PIN_BACKLIGHT PTA1
Rhyme 0:227c21cd26be 69 #endif
Rhyme 0:227c21cd26be 70
Rhyme 0:227c21cd26be 71
Rhyme 0:227c21cd26be 72 #define MMA8451_I2C_ADDRESS (0x1d<<1)
Rhyme 0:227c21cd26be 73 MMA8451Q *acc = 0 ;
Rhyme 0:227c21cd26be 74
Rhyme 0:227c21cd26be 75 // SeeedStudioTFTv2 TFT(PIN_XP, PIN_XM, PIN_YP, PIN_YM, PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_DC_TFT, PIN_BL_TFT, PIN_CS_SD);
Rhyme 0:227c21cd26be 76 // SPI_TFT_ILI9341(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName dc, const char* name ="TFT");
Rhyme 0:227c21cd26be 77 SPI_TFT_ILI9341 TFT(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_BL_TFT, PIN_DC_TFT) ;
Rhyme 0:227c21cd26be 78 SPI_STMPE610 TSC(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ;
Rhyme 0:227c21cd26be 79
Rhyme 0:227c21cd26be 80 DigitalOut backlight(PIN_BACKLIGHT) ;
Rhyme 0:227c21cd26be 81 DigitalIn pinD7(PIN_TSC_INTR) ;
Rhyme 0:227c21cd26be 82
Rhyme 0:227c21cd26be 83 int page = 0 ;
Rhyme 0:227c21cd26be 84 int numPage = 3 ;
Rhyme 0:227c21cd26be 85
Rhyme 0:227c21cd26be 86 void initTFT(void)
Rhyme 0:227c21cd26be 87 {
Rhyme 0:227c21cd26be 88 //Configure the display driver
Rhyme 0:227c21cd26be 89 TFT.background(Black);
Rhyme 0:227c21cd26be 90 TFT.foreground(White);
Rhyme 0:227c21cd26be 91 wait(0.01) ;
Rhyme 0:227c21cd26be 92 TFT.cls();
Rhyme 0:227c21cd26be 93 }
Rhyme 0:227c21cd26be 94
Rhyme 0:227c21cd26be 95 void screen1(void) // Welcome Screen
Rhyme 0:227c21cd26be 96 {
Rhyme 0:227c21cd26be 97 backlight = 0 ;
Rhyme 0:227c21cd26be 98 TFT.background(White) ;
Rhyme 0:227c21cd26be 99 TFT.cls() ;
Rhyme 0:227c21cd26be 100
Rhyme 0:227c21cd26be 101 wait(0.1) ;
Rhyme 0:227c21cd26be 102 TFT.set_font((unsigned char*) Arial24x23);
Rhyme 0:227c21cd26be 103 TFT.foreground(Red) ;
Rhyme 0:227c21cd26be 104 TFT.locate(80, 40) ;
Rhyme 0:227c21cd26be 105 TFT.printf("mbed") ;
Rhyme 0:227c21cd26be 106 TFT.foreground(Blue);
Rhyme 0:227c21cd26be 107 TFT.locate(60, 80) ;
Rhyme 0:227c21cd26be 108 TFT.printf("TFT 2.8\"") ;
Rhyme 0:227c21cd26be 109 TFT.locate(40, 120) ;
Rhyme 0:227c21cd26be 110 TFT.printf("with touch") ;
Rhyme 0:227c21cd26be 111 TFT.foreground(Black);
Rhyme 0:227c21cd26be 112 TFT.set_font((unsigned char*) Arial12x12);
Rhyme 0:227c21cd26be 113 TFT.foreground(Blue) ;
Rhyme 0:227c21cd26be 114 TFT.locate(10, 180) ;
Rhyme 0:227c21cd26be 115 TFT.printf("This program is running on") ;
Rhyme 0:227c21cd26be 116 TFT.locate(10, 200) ;
Rhyme 0:227c21cd26be 117 TFT.printf("freescale FRDM-K64F with") ;
Rhyme 0:227c21cd26be 118 TFT.locate(10, 220) ;
Rhyme 0:227c21cd26be 119 TFT.printf("a program developed on mbed") ;
Rhyme 0:227c21cd26be 120 TFT.foreground(Green) ;
Rhyme 0:227c21cd26be 121 TFT.locate(10, 260) ;
Rhyme 0:227c21cd26be 122 TFT.printf("To advance demo page, touch") ;
Rhyme 0:227c21cd26be 123 TFT.locate(10, 280) ;
Rhyme 0:227c21cd26be 124 TFT.printf("and hold right side of screen") ;
Rhyme 0:227c21cd26be 125 TFT.locate(10, 300) ;
Rhyme 0:227c21cd26be 126 TFT.printf("until the next screen starts") ;
Rhyme 0:227c21cd26be 127 backlight = 1 ;
Rhyme 0:227c21cd26be 128 }
Rhyme 0:227c21cd26be 129
Rhyme 0:227c21cd26be 130 void screen2(void) // Graphics
Rhyme 0:227c21cd26be 131 {
Rhyme 0:227c21cd26be 132 //Draw some graphics
Rhyme 0:227c21cd26be 133 int i, x[2], y[2] ;
Rhyme 0:227c21cd26be 134 backlight = 0 ;
Rhyme 0:227c21cd26be 135
Rhyme 0:227c21cd26be 136 TFT.background(Black);
Rhyme 0:227c21cd26be 137 TFT.foreground(White);
Rhyme 0:227c21cd26be 138 TFT.cls() ;
Rhyme 0:227c21cd26be 139 TFT.set_font((unsigned char*) Arial12x12);
Rhyme 0:227c21cd26be 140 TFT.locate(90,0);
Rhyme 0:227c21cd26be 141 TFT.printf("Graphics");
Rhyme 0:227c21cd26be 142
Rhyme 0:227c21cd26be 143 x[0] = 25 ; x[1] = 224 ;
Rhyme 0:227c21cd26be 144 y[0] = 20 ; y[1] = 219 ;
Rhyme 0:227c21cd26be 145 for (i = 20 ; i < 220 ; i += 10) {
Rhyme 0:227c21cd26be 146 TFT.line(i+5, y[0], i+5, y[1], Blue) ;
Rhyme 0:227c21cd26be 147 TFT.line(x[0], i, x[1], i, Blue) ;
Rhyme 0:227c21cd26be 148 }
Rhyme 0:227c21cd26be 149 TFT.line(125, y[0], 125, y[1], Green) ;
Rhyme 0:227c21cd26be 150 TFT.line(x[0], 120, x[1], 120, Green) ;
Rhyme 0:227c21cd26be 151 TFT.rect(x[0],y[0], x[1], y[1], Green) ;
Rhyme 0:227c21cd26be 152 TFT.locate(10, 20) ;
Rhyme 0:227c21cd26be 153 TFT.printf("V") ;
Rhyme 0:227c21cd26be 154 TFT.locate(0, 115) ;
Rhyme 0:227c21cd26be 155 TFT.printf("0.0") ;
Rhyme 0:227c21cd26be 156 TFT.locate(115, 225) ;
Rhyme 0:227c21cd26be 157 TFT.printf("0.0") ;
Rhyme 0:227c21cd26be 158 TFT.locate(215, 225) ;
Rhyme 0:227c21cd26be 159 TFT.printf("T") ;
Rhyme 0:227c21cd26be 160
Rhyme 0:227c21cd26be 161 double s;
Rhyme 0:227c21cd26be 162 for (int i = x[0]; i < 225; i++) {
Rhyme 0:227c21cd26be 163 s = 40 * sin((long double)i / 20);
Rhyme 0:227c21cd26be 164 TFT.pixel(i, 120 + (int)s, White);
Rhyme 0:227c21cd26be 165 }
Rhyme 0:227c21cd26be 166
Rhyme 0:227c21cd26be 167 TFT.fillrect(10, 240, 229, 309, White) ;
Rhyme 0:227c21cd26be 168 TFT.rect(10, 240, 229, 309, Red) ;
Rhyme 0:227c21cd26be 169 TFT.rect(11, 241, 228, 308, Red) ;
Rhyme 0:227c21cd26be 170
Rhyme 0:227c21cd26be 171 TFT.background(White) ;
Rhyme 0:227c21cd26be 172 TFT.foreground(Black) ;
Rhyme 0:227c21cd26be 173 TFT.locate(20, 250) ;
Rhyme 0:227c21cd26be 174 TFT.printf("With QVGA resolution") ;
Rhyme 0:227c21cd26be 175 TFT.locate(20, 270) ;
Rhyme 0:227c21cd26be 176 TFT.printf("simple graphics drawing") ;
Rhyme 0:227c21cd26be 177 TFT.locate(20, 290) ;
Rhyme 0:227c21cd26be 178 TFT.printf("capability is provided") ;
Rhyme 0:227c21cd26be 179 backlight = 1 ;
Rhyme 0:227c21cd26be 180 }
Rhyme 0:227c21cd26be 181
Rhyme 0:227c21cd26be 182 double clip(double src)
Rhyme 0:227c21cd26be 183 {
Rhyme 0:227c21cd26be 184 double value ;
Rhyme 0:227c21cd26be 185 value = src ;
Rhyme 0:227c21cd26be 186 if (value < 0.0) {
Rhyme 0:227c21cd26be 187 value = 0.0 ;
Rhyme 0:227c21cd26be 188 } else if (value > 2.0) {
Rhyme 0:227c21cd26be 189 value = 2.0 ;
Rhyme 0:227c21cd26be 190 }
Rhyme 0:227c21cd26be 191 return( value ) ;
Rhyme 0:227c21cd26be 192 }
Rhyme 0:227c21cd26be 193
Rhyme 0:227c21cd26be 194 void screen3(void)
Rhyme 0:227c21cd26be 195 {
Rhyme 0:227c21cd26be 196 int t = 0 ;
Rhyme 0:227c21cd26be 197 int pt = 0 ; // previous t
Rhyme 0:227c21cd26be 198 int i, x, y ;
Rhyme 0:227c21cd26be 199 unsigned int data[3] ; // for x, y, z
Rhyme 0:227c21cd26be 200 unsigned int prev[3] ;
Rhyme 0:227c21cd26be 201 unsigned short signalHeight = 39 ;
Rhyme 0:227c21cd26be 202 unsigned short xoffset = 30 ;
Rhyme 0:227c21cd26be 203 unsigned short yoffset = 120 ;
Rhyme 0:227c21cd26be 204 unsigned short zoffset = 210 ;
Rhyme 0:227c21cd26be 205 unsigned short paneX[2] = {20, 235} ;
Rhyme 0:227c21cd26be 206 unsigned short paneH = 81 ;
Rhyme 0:227c21cd26be 207
Rhyme 0:227c21cd26be 208 backlight = 0 ;
Rhyme 0:227c21cd26be 209 TFT.background(Black) ;
Rhyme 0:227c21cd26be 210 TFT.foreground(White) ;
Rhyme 0:227c21cd26be 211 // TFT.cls() ;
Rhyme 0:227c21cd26be 212
Rhyme 0:227c21cd26be 213
Rhyme 0:227c21cd26be 214 TFT.fillrect(paneX[0], xoffset, paneX[1], xoffset+paneH, Black) ;
Rhyme 0:227c21cd26be 215 TFT.fillrect(paneX[0], yoffset, paneX[1], yoffset+paneH, Black) ;
Rhyme 0:227c21cd26be 216 TFT.fillrect(paneX[0], zoffset, paneX[1], zoffset+paneH, Black) ;
Rhyme 0:227c21cd26be 217 TFT.fillrect(paneX[0], xoffset, paneX[1], xoffset+paneH, Black) ;
Rhyme 0:227c21cd26be 218 for (i = 0 ; i < 10 ; i++ ) {
Rhyme 0:227c21cd26be 219 y = i * 8 ;
Rhyme 0:227c21cd26be 220 TFT.line(paneX[0], xoffset + y, paneX[1], xoffset + y, Blue) ;
Rhyme 0:227c21cd26be 221 TFT.line(paneX[0], yoffset + y, paneX[1], yoffset + y, Blue) ;
Rhyme 0:227c21cd26be 222 TFT.line(paneX[0], zoffset + y, paneX[1], zoffset + y, Blue) ;
Rhyme 0:227c21cd26be 223 }
Rhyme 0:227c21cd26be 224 for (x = 30 ; x < paneX[1] ; x += 10 ) {
Rhyme 0:227c21cd26be 225 TFT.line(x, xoffset, x, xoffset+paneH, Blue) ;
Rhyme 0:227c21cd26be 226 TFT.line(x, yoffset, x, yoffset+paneH, Blue) ;
Rhyme 0:227c21cd26be 227 TFT.line(x, zoffset, x, zoffset+paneH, Blue) ;
Rhyme 0:227c21cd26be 228 }
Rhyme 0:227c21cd26be 229 TFT.rect(paneX[0], xoffset, paneX[1], xoffset+paneH, White) ;
Rhyme 0:227c21cd26be 230 TFT.rect(paneX[0], yoffset, paneX[1], yoffset+paneH, White) ;
Rhyme 0:227c21cd26be 231 TFT.rect(paneX[0], zoffset, paneX[1], zoffset+paneH, White) ;
Rhyme 0:227c21cd26be 232 TFT.set_font((unsigned char*) Arial12x12);
Rhyme 0:227c21cd26be 233 TFT.locate(5, xoffset+30) ;
Rhyme 0:227c21cd26be 234 TFT.printf("X") ;
Rhyme 0:227c21cd26be 235 TFT.locate(5, yoffset+30) ;
Rhyme 0:227c21cd26be 236 TFT.printf("Y") ;
Rhyme 0:227c21cd26be 237 TFT.locate(5, zoffset+30) ;
Rhyme 0:227c21cd26be 238 TFT.printf("Z") ;
Rhyme 0:227c21cd26be 239 TFT.locate(50, 10) ;
Rhyme 0:227c21cd26be 240 TFT.printf("Xtrinsic Accelerometer") ;
Rhyme 0:227c21cd26be 241 TFT.locate(90, 300) ;
Rhyme 0:227c21cd26be 242 TFT.printf("MMA8451Q") ;
Rhyme 0:227c21cd26be 243
Rhyme 0:227c21cd26be 244 prev[0] = xoffset + (signalHeight * clip((1.0 + acc->getAccX()))) ;
Rhyme 0:227c21cd26be 245 prev[1] = yoffset + (signalHeight * clip((1.0 + acc->getAccY()))) ;
Rhyme 0:227c21cd26be 246 prev[2] = zoffset + (signalHeight * clip((1.0 + acc->getAccZ()))) ;
Rhyme 0:227c21cd26be 247 pt = paneX[0] ;
Rhyme 0:227c21cd26be 248 backlight = 1 ;
Rhyme 0:227c21cd26be 249 for(t = 21 ; t < paneX[1] ; t++) {
Rhyme 0:227c21cd26be 250 data[0] = xoffset + (signalHeight * clip((1.0 + acc->getAccX()))) ;
Rhyme 0:227c21cd26be 251 data[1] = yoffset + (signalHeight * clip((1.0 + acc->getAccY()))) ;
Rhyme 0:227c21cd26be 252 data[2] = zoffset + (signalHeight * clip((1.0 + acc->getAccZ()))) ;
Rhyme 0:227c21cd26be 253 TFT.line(pt, prev[0], t, data[0], Red) ;
Rhyme 0:227c21cd26be 254 TFT.line(pt, prev[1], t, data[1], Green) ;
Rhyme 0:227c21cd26be 255 TFT.line(pt, prev[2], t, data[2], Yellow) ;
Rhyme 0:227c21cd26be 256 prev[0] = data[0] ;
Rhyme 0:227c21cd26be 257 prev[1] = data[1] ;
Rhyme 0:227c21cd26be 258 prev[2] = data[2] ;
Rhyme 0:227c21cd26be 259 pt = t ;
Rhyme 0:227c21cd26be 260 wait(0.01) ;
Rhyme 0:227c21cd26be 261 }
Rhyme 0:227c21cd26be 262 }
Rhyme 0:227c21cd26be 263
Rhyme 0:227c21cd26be 264 void incPage(void)
Rhyme 0:227c21cd26be 265 {
Rhyme 0:227c21cd26be 266 page++ ;
Rhyme 0:227c21cd26be 267 if (page >= numPage) {
Rhyme 0:227c21cd26be 268 page = 0 ;
Rhyme 0:227c21cd26be 269 }
Rhyme 0:227c21cd26be 270 }
Rhyme 0:227c21cd26be 271
Rhyme 0:227c21cd26be 272 void decPage(void)
Rhyme 0:227c21cd26be 273 {
Rhyme 0:227c21cd26be 274 page-- ;
Rhyme 0:227c21cd26be 275 if (page < 0) {
Rhyme 0:227c21cd26be 276 page = numPage - 1 ;
Rhyme 0:227c21cd26be 277 }
Rhyme 0:227c21cd26be 278 }
Rhyme 0:227c21cd26be 279
Rhyme 0:227c21cd26be 280 int main()
Rhyme 0:227c21cd26be 281 {
Rhyme 0:227c21cd26be 282 uint16_t x, y, z ;
Rhyme 0:227c21cd26be 283 int prevPage = 0 ;
Rhyme 0:227c21cd26be 284 int touched = 0 ;
Rhyme 0:227c21cd26be 285
Rhyme 0:227c21cd26be 286
Rhyme 0:227c21cd26be 287
Rhyme 0:227c21cd26be 288 initTFT() ;
Rhyme 0:227c21cd26be 289
Rhyme 0:227c21cd26be 290 screen1() ;
Rhyme 0:227c21cd26be 291
Rhyme 0:227c21cd26be 292 printf("Program Started!\n\r") ;
Rhyme 0:227c21cd26be 293
Rhyme 0:227c21cd26be 294 acc = new MMA8451Q(PTE25, PTE24, MMA8451_I2C_ADDRESS) ;
Rhyme 0:227c21cd26be 295
Rhyme 0:227c21cd26be 296 for(;;) {
Rhyme 0:227c21cd26be 297 // printf("TFT width = %d, height = %d\n\r", TFT.width(), TFT.height()) ;
Rhyme 0:227c21cd26be 298 switch(page) {
Rhyme 0:227c21cd26be 299 case 0:
Rhyme 0:227c21cd26be 300 if (prevPage != page) {
Rhyme 0:227c21cd26be 301 screen1() ;
Rhyme 0:227c21cd26be 302 }
Rhyme 0:227c21cd26be 303 wait(1) ;
Rhyme 0:227c21cd26be 304 break ;
Rhyme 0:227c21cd26be 305 case 1:
Rhyme 0:227c21cd26be 306 if (prevPage != page) {
Rhyme 0:227c21cd26be 307 screen2() ;
Rhyme 0:227c21cd26be 308 }
Rhyme 0:227c21cd26be 309 wait(1) ;
Rhyme 0:227c21cd26be 310 break ;
Rhyme 0:227c21cd26be 311 case 2:
Rhyme 0:227c21cd26be 312 if (prevPage != page) {
Rhyme 0:227c21cd26be 313 TFT.background(Black) ;
Rhyme 0:227c21cd26be 314 TFT.foreground(White) ;
Rhyme 0:227c21cd26be 315 TFT.cls() ;
Rhyme 0:227c21cd26be 316 }
Rhyme 0:227c21cd26be 317 screen3() ;
Rhyme 0:227c21cd26be 318 wait(2) ;
Rhyme 0:227c21cd26be 319 break ;
Rhyme 0:227c21cd26be 320 default:
Rhyme 0:227c21cd26be 321 page = 0 ;
Rhyme 0:227c21cd26be 322 break ;
Rhyme 0:227c21cd26be 323 }
Rhyme 0:227c21cd26be 324 prevPage = page ;
Rhyme 0:227c21cd26be 325 printf("Screen Printed\n\r") ;
Rhyme 0:227c21cd26be 326
Rhyme 0:227c21cd26be 327 x = 0 ; y = 0 ; z = 0 ;
Rhyme 0:227c21cd26be 328 touched = TSC.getRAWPoint(&x, &y, &z) ;
Rhyme 0:227c21cd26be 329 printf("touched = %d x = %d, y = %d, z = %d\n\r",touched, x,y,z) ;
Rhyme 0:227c21cd26be 330 if ((x != 0)||(y != 0) || (z != 0)) {
Rhyme 0:227c21cd26be 331 if (x < 1000) { // left
Rhyme 0:227c21cd26be 332 decPage() ;
Rhyme 0:227c21cd26be 333 } else if (x > 3000) { // right
Rhyme 0:227c21cd26be 334 incPage() ;
Rhyme 0:227c21cd26be 335 }
Rhyme 0:227c21cd26be 336 }
Rhyme 0:227c21cd26be 337 // wait(1) ;
Rhyme 0:227c21cd26be 338 }
Rhyme 0:227c21cd26be 339 }