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:58:15 2014 +0000
Revision:
1:5ea1dc8f875f
Parent:
0:227c21cd26be
Child:
3:5b9647f22941
Header description corrected for this project

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 1:5ea1dc8f875f 1 /* mbed main.cpp to test adafruit 2.8" TFT LCD shiled w Touchscreen
Rhyme 1:5ea1dc8f875f 2 * Copyright (c) 2014 Motoo Tanaka @ Design Methodology Lab
Rhyme 1:5ea1dc8f875f 3 *
Rhyme 1:5ea1dc8f875f 4 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Rhyme 1:5ea1dc8f875f 5 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Rhyme 1:5ea1dc8f875f 6 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Rhyme 1:5ea1dc8f875f 7 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Rhyme 1:5ea1dc8f875f 8 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Rhyme 1:5ea1dc8f875f 9 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Rhyme 1:5ea1dc8f875f 10 * THE SOFTWARE.
Rhyme 1:5ea1dc8f875f 11 */
Rhyme 1:5ea1dc8f875f 12
Rhyme 1:5ea1dc8f875f 13 /* *
Rhyme 1:5ea1dc8f875f 14 * @note This program is derived from the SeeeStudioTFTv2 program.
Rhyme 1:5ea1dc8f875f 15 * @note Although both program share same ILI9341 TFT driver,
Rhyme 1:5ea1dc8f875f 16 * @note the touch sensor was not same with the Display I purchased from Akizuki.
Rhyme 1:5ea1dc8f875f 17 * @note http://akizukidenshi.com/catalog/g/gM-07747/
Rhyme 1:5ea1dc8f875f 18 * @note The touch sensor on the display is STMPE610,
Rhyme 1:5ea1dc8f875f 19 * @note so I hacked the minimum spi driver for it (polling mode only).
Rhyme 1:5ea1dc8f875f 20 */
Rhyme 1:5ea1dc8f875f 21 /**
Rhyme 1:5ea1dc8f875f 22 * @note To make this work with FRDM-K64F
Rhyme 1:5ea1dc8f875f 23 * @note PTA0 must be disconnected from the swd clk by cutting J11.
Rhyme 1:5ea1dc8f875f 24 * @note But to re-active SWD you need to put jumper header to J11
Rhyme 1:5ea1dc8f875f 25 * @note so that it can be re-connected by a jumper.
Rhyme 1:5ea1dc8f875f 26 */
Rhyme 0:227c21cd26be 27
Rhyme 0:227c21cd26be 28 #include "mbed.h"
Rhyme 0:227c21cd26be 29 #include "MMA8451Q.h"
Rhyme 0:227c21cd26be 30 #include <math.h>
Rhyme 0:227c21cd26be 31 #include "SPI_TFT_ILI9341.h"
Rhyme 0:227c21cd26be 32 #include "SPI_STMPE610.h"
Rhyme 0:227c21cd26be 33 #include "Arial12x12.h"
Rhyme 0:227c21cd26be 34 #include "Arial24x23.h"
Rhyme 0:227c21cd26be 35 #include "Arial28x28.h"
Rhyme 0:227c21cd26be 36 #include "font_big.h"
Rhyme 0:227c21cd26be 37
Rhyme 0:227c21cd26be 38 #if 0
Rhyme 0:227c21cd26be 39 /*
Rhyme 0:227c21cd26be 40 // For FRDM-KL25Z
Rhyme 0:227c21cd26be 41 #define PIN_XP PTB3
Rhyme 0:227c21cd26be 42 #define PIN_XM PTB1
Rhyme 0:227c21cd26be 43 #define PIN_YP PTB2
Rhyme 0:227c21cd26be 44 #define PIN_YM PTB0
Rhyme 0:227c21cd26be 45 #define PIN_MOSI PTD2
Rhyme 0:227c21cd26be 46 #define PIN_MISO PTD3
Rhyme 0:227c21cd26be 47 #define PIN_SCLK PTD1
Rhyme 0:227c21cd26be 48 #define PIN_CS_TFT PTD0
Rhyme 0:227c21cd26be 49 #define PIN_DC_TFT PTD5
Rhyme 0:227c21cd26be 50 #define PIN_BL_TFT PTC9
Rhyme 0:227c21cd26be 51 #define PIN_CS_SD PTA4
Rhyme 0:227c21cd26be 52 #define PIN_CS_TSC PTA13
Rhyme 0:227c21cd26be 53 #define PIN_TSC_INTR PTC9
Rhyme 0:227c21cd26be 54 #define PIN_BACKLIGHT PTA12
Rhyme 0:227c21cd26be 55 */
Rhyme 0:227c21cd26be 56 #endif
Rhyme 0:227c21cd26be 57
Rhyme 0:227c21cd26be 58 #if 1
Rhyme 0:227c21cd26be 59 // For FRDM-K64F
Rhyme 0:227c21cd26be 60 #define PIN_XP PTB11
Rhyme 0:227c21cd26be 61 #define PIN_XM PTB3
Rhyme 0:227c21cd26be 62 #define PIN_YP PTB10
Rhyme 0:227c21cd26be 63 #define PIN_YM PTB2
Rhyme 0:227c21cd26be 64 #define PIN_MOSI PTD2
Rhyme 0:227c21cd26be 65 #define PIN_MISO PTD3
Rhyme 0:227c21cd26be 66 #define PIN_SCLK PTD1
Rhyme 0:227c21cd26be 67 #define PIN_CS_TFT PTD0
Rhyme 0:227c21cd26be 68 #define PIN_DC_TFT PTC4
Rhyme 0:227c21cd26be 69 #define PIN_BL_TFT PTC3
Rhyme 0:227c21cd26be 70 #define PIN_CS_SD PTB23
Rhyme 0:227c21cd26be 71 #define PIN_CS_TSC PTA0
Rhyme 0:227c21cd26be 72 #define PIN_TSC_INTR PTC3
Rhyme 0:227c21cd26be 73 #define PIN_BACKLIGHT PTA1
Rhyme 0:227c21cd26be 74 #endif
Rhyme 0:227c21cd26be 75
Rhyme 0:227c21cd26be 76
Rhyme 0:227c21cd26be 77 #define MMA8451_I2C_ADDRESS (0x1d<<1)
Rhyme 0:227c21cd26be 78 MMA8451Q *acc = 0 ;
Rhyme 0:227c21cd26be 79
Rhyme 0:227c21cd26be 80 // 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 81 // SPI_TFT_ILI9341(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName dc, const char* name ="TFT");
Rhyme 0:227c21cd26be 82 SPI_TFT_ILI9341 TFT(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_BL_TFT, PIN_DC_TFT) ;
Rhyme 0:227c21cd26be 83 SPI_STMPE610 TSC(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ;
Rhyme 0:227c21cd26be 84
Rhyme 0:227c21cd26be 85 DigitalOut backlight(PIN_BACKLIGHT) ;
Rhyme 0:227c21cd26be 86 DigitalIn pinD7(PIN_TSC_INTR) ;
Rhyme 0:227c21cd26be 87
Rhyme 0:227c21cd26be 88 int page = 0 ;
Rhyme 0:227c21cd26be 89 int numPage = 3 ;
Rhyme 0:227c21cd26be 90
Rhyme 0:227c21cd26be 91 void initTFT(void)
Rhyme 0:227c21cd26be 92 {
Rhyme 0:227c21cd26be 93 //Configure the display driver
Rhyme 0:227c21cd26be 94 TFT.background(Black);
Rhyme 0:227c21cd26be 95 TFT.foreground(White);
Rhyme 0:227c21cd26be 96 wait(0.01) ;
Rhyme 0:227c21cd26be 97 TFT.cls();
Rhyme 0:227c21cd26be 98 }
Rhyme 0:227c21cd26be 99
Rhyme 0:227c21cd26be 100 void screen1(void) // Welcome Screen
Rhyme 0:227c21cd26be 101 {
Rhyme 0:227c21cd26be 102 backlight = 0 ;
Rhyme 0:227c21cd26be 103 TFT.background(White) ;
Rhyme 0:227c21cd26be 104 TFT.cls() ;
Rhyme 0:227c21cd26be 105
Rhyme 0:227c21cd26be 106 wait(0.1) ;
Rhyme 0:227c21cd26be 107 TFT.set_font((unsigned char*) Arial24x23);
Rhyme 0:227c21cd26be 108 TFT.foreground(Red) ;
Rhyme 0:227c21cd26be 109 TFT.locate(80, 40) ;
Rhyme 0:227c21cd26be 110 TFT.printf("mbed") ;
Rhyme 0:227c21cd26be 111 TFT.foreground(Blue);
Rhyme 0:227c21cd26be 112 TFT.locate(60, 80) ;
Rhyme 0:227c21cd26be 113 TFT.printf("TFT 2.8\"") ;
Rhyme 0:227c21cd26be 114 TFT.locate(40, 120) ;
Rhyme 0:227c21cd26be 115 TFT.printf("with touch") ;
Rhyme 0:227c21cd26be 116 TFT.foreground(Black);
Rhyme 0:227c21cd26be 117 TFT.set_font((unsigned char*) Arial12x12);
Rhyme 0:227c21cd26be 118 TFT.foreground(Blue) ;
Rhyme 0:227c21cd26be 119 TFT.locate(10, 180) ;
Rhyme 0:227c21cd26be 120 TFT.printf("This program is running on") ;
Rhyme 0:227c21cd26be 121 TFT.locate(10, 200) ;
Rhyme 0:227c21cd26be 122 TFT.printf("freescale FRDM-K64F with") ;
Rhyme 0:227c21cd26be 123 TFT.locate(10, 220) ;
Rhyme 0:227c21cd26be 124 TFT.printf("a program developed on mbed") ;
Rhyme 0:227c21cd26be 125 TFT.foreground(Green) ;
Rhyme 0:227c21cd26be 126 TFT.locate(10, 260) ;
Rhyme 0:227c21cd26be 127 TFT.printf("To advance demo page, touch") ;
Rhyme 0:227c21cd26be 128 TFT.locate(10, 280) ;
Rhyme 0:227c21cd26be 129 TFT.printf("and hold right side of screen") ;
Rhyme 0:227c21cd26be 130 TFT.locate(10, 300) ;
Rhyme 0:227c21cd26be 131 TFT.printf("until the next screen starts") ;
Rhyme 0:227c21cd26be 132 backlight = 1 ;
Rhyme 0:227c21cd26be 133 }
Rhyme 0:227c21cd26be 134
Rhyme 0:227c21cd26be 135 void screen2(void) // Graphics
Rhyme 0:227c21cd26be 136 {
Rhyme 0:227c21cd26be 137 //Draw some graphics
Rhyme 0:227c21cd26be 138 int i, x[2], y[2] ;
Rhyme 0:227c21cd26be 139 backlight = 0 ;
Rhyme 0:227c21cd26be 140
Rhyme 0:227c21cd26be 141 TFT.background(Black);
Rhyme 0:227c21cd26be 142 TFT.foreground(White);
Rhyme 0:227c21cd26be 143 TFT.cls() ;
Rhyme 0:227c21cd26be 144 TFT.set_font((unsigned char*) Arial12x12);
Rhyme 0:227c21cd26be 145 TFT.locate(90,0);
Rhyme 0:227c21cd26be 146 TFT.printf("Graphics");
Rhyme 0:227c21cd26be 147
Rhyme 0:227c21cd26be 148 x[0] = 25 ; x[1] = 224 ;
Rhyme 0:227c21cd26be 149 y[0] = 20 ; y[1] = 219 ;
Rhyme 0:227c21cd26be 150 for (i = 20 ; i < 220 ; i += 10) {
Rhyme 0:227c21cd26be 151 TFT.line(i+5, y[0], i+5, y[1], Blue) ;
Rhyme 0:227c21cd26be 152 TFT.line(x[0], i, x[1], i, Blue) ;
Rhyme 0:227c21cd26be 153 }
Rhyme 0:227c21cd26be 154 TFT.line(125, y[0], 125, y[1], Green) ;
Rhyme 0:227c21cd26be 155 TFT.line(x[0], 120, x[1], 120, Green) ;
Rhyme 0:227c21cd26be 156 TFT.rect(x[0],y[0], x[1], y[1], Green) ;
Rhyme 0:227c21cd26be 157 TFT.locate(10, 20) ;
Rhyme 0:227c21cd26be 158 TFT.printf("V") ;
Rhyme 0:227c21cd26be 159 TFT.locate(0, 115) ;
Rhyme 0:227c21cd26be 160 TFT.printf("0.0") ;
Rhyme 0:227c21cd26be 161 TFT.locate(115, 225) ;
Rhyme 0:227c21cd26be 162 TFT.printf("0.0") ;
Rhyme 0:227c21cd26be 163 TFT.locate(215, 225) ;
Rhyme 0:227c21cd26be 164 TFT.printf("T") ;
Rhyme 0:227c21cd26be 165
Rhyme 0:227c21cd26be 166 double s;
Rhyme 0:227c21cd26be 167 for (int i = x[0]; i < 225; i++) {
Rhyme 0:227c21cd26be 168 s = 40 * sin((long double)i / 20);
Rhyme 0:227c21cd26be 169 TFT.pixel(i, 120 + (int)s, White);
Rhyme 0:227c21cd26be 170 }
Rhyme 0:227c21cd26be 171
Rhyme 0:227c21cd26be 172 TFT.fillrect(10, 240, 229, 309, White) ;
Rhyme 0:227c21cd26be 173 TFT.rect(10, 240, 229, 309, Red) ;
Rhyme 0:227c21cd26be 174 TFT.rect(11, 241, 228, 308, Red) ;
Rhyme 0:227c21cd26be 175
Rhyme 0:227c21cd26be 176 TFT.background(White) ;
Rhyme 0:227c21cd26be 177 TFT.foreground(Black) ;
Rhyme 0:227c21cd26be 178 TFT.locate(20, 250) ;
Rhyme 0:227c21cd26be 179 TFT.printf("With QVGA resolution") ;
Rhyme 0:227c21cd26be 180 TFT.locate(20, 270) ;
Rhyme 0:227c21cd26be 181 TFT.printf("simple graphics drawing") ;
Rhyme 0:227c21cd26be 182 TFT.locate(20, 290) ;
Rhyme 0:227c21cd26be 183 TFT.printf("capability is provided") ;
Rhyme 0:227c21cd26be 184 backlight = 1 ;
Rhyme 0:227c21cd26be 185 }
Rhyme 0:227c21cd26be 186
Rhyme 0:227c21cd26be 187 double clip(double src)
Rhyme 0:227c21cd26be 188 {
Rhyme 0:227c21cd26be 189 double value ;
Rhyme 0:227c21cd26be 190 value = src ;
Rhyme 0:227c21cd26be 191 if (value < 0.0) {
Rhyme 0:227c21cd26be 192 value = 0.0 ;
Rhyme 0:227c21cd26be 193 } else if (value > 2.0) {
Rhyme 0:227c21cd26be 194 value = 2.0 ;
Rhyme 0:227c21cd26be 195 }
Rhyme 0:227c21cd26be 196 return( value ) ;
Rhyme 0:227c21cd26be 197 }
Rhyme 0:227c21cd26be 198
Rhyme 0:227c21cd26be 199 void screen3(void)
Rhyme 0:227c21cd26be 200 {
Rhyme 0:227c21cd26be 201 int t = 0 ;
Rhyme 0:227c21cd26be 202 int pt = 0 ; // previous t
Rhyme 0:227c21cd26be 203 int i, x, y ;
Rhyme 0:227c21cd26be 204 unsigned int data[3] ; // for x, y, z
Rhyme 0:227c21cd26be 205 unsigned int prev[3] ;
Rhyme 0:227c21cd26be 206 unsigned short signalHeight = 39 ;
Rhyme 0:227c21cd26be 207 unsigned short xoffset = 30 ;
Rhyme 0:227c21cd26be 208 unsigned short yoffset = 120 ;
Rhyme 0:227c21cd26be 209 unsigned short zoffset = 210 ;
Rhyme 0:227c21cd26be 210 unsigned short paneX[2] = {20, 235} ;
Rhyme 0:227c21cd26be 211 unsigned short paneH = 81 ;
Rhyme 0:227c21cd26be 212
Rhyme 0:227c21cd26be 213 backlight = 0 ;
Rhyme 0:227c21cd26be 214 TFT.background(Black) ;
Rhyme 0:227c21cd26be 215 TFT.foreground(White) ;
Rhyme 0:227c21cd26be 216 // TFT.cls() ;
Rhyme 0:227c21cd26be 217
Rhyme 0:227c21cd26be 218
Rhyme 0:227c21cd26be 219 TFT.fillrect(paneX[0], xoffset, paneX[1], xoffset+paneH, Black) ;
Rhyme 0:227c21cd26be 220 TFT.fillrect(paneX[0], yoffset, paneX[1], yoffset+paneH, Black) ;
Rhyme 0:227c21cd26be 221 TFT.fillrect(paneX[0], zoffset, paneX[1], zoffset+paneH, Black) ;
Rhyme 0:227c21cd26be 222 TFT.fillrect(paneX[0], xoffset, paneX[1], xoffset+paneH, Black) ;
Rhyme 0:227c21cd26be 223 for (i = 0 ; i < 10 ; i++ ) {
Rhyme 0:227c21cd26be 224 y = i * 8 ;
Rhyme 0:227c21cd26be 225 TFT.line(paneX[0], xoffset + y, paneX[1], xoffset + y, Blue) ;
Rhyme 0:227c21cd26be 226 TFT.line(paneX[0], yoffset + y, paneX[1], yoffset + y, Blue) ;
Rhyme 0:227c21cd26be 227 TFT.line(paneX[0], zoffset + y, paneX[1], zoffset + y, Blue) ;
Rhyme 0:227c21cd26be 228 }
Rhyme 0:227c21cd26be 229 for (x = 30 ; x < paneX[1] ; x += 10 ) {
Rhyme 0:227c21cd26be 230 TFT.line(x, xoffset, x, xoffset+paneH, Blue) ;
Rhyme 0:227c21cd26be 231 TFT.line(x, yoffset, x, yoffset+paneH, Blue) ;
Rhyme 0:227c21cd26be 232 TFT.line(x, zoffset, x, zoffset+paneH, Blue) ;
Rhyme 0:227c21cd26be 233 }
Rhyme 0:227c21cd26be 234 TFT.rect(paneX[0], xoffset, paneX[1], xoffset+paneH, White) ;
Rhyme 0:227c21cd26be 235 TFT.rect(paneX[0], yoffset, paneX[1], yoffset+paneH, White) ;
Rhyme 0:227c21cd26be 236 TFT.rect(paneX[0], zoffset, paneX[1], zoffset+paneH, White) ;
Rhyme 0:227c21cd26be 237 TFT.set_font((unsigned char*) Arial12x12);
Rhyme 0:227c21cd26be 238 TFT.locate(5, xoffset+30) ;
Rhyme 0:227c21cd26be 239 TFT.printf("X") ;
Rhyme 0:227c21cd26be 240 TFT.locate(5, yoffset+30) ;
Rhyme 0:227c21cd26be 241 TFT.printf("Y") ;
Rhyme 0:227c21cd26be 242 TFT.locate(5, zoffset+30) ;
Rhyme 0:227c21cd26be 243 TFT.printf("Z") ;
Rhyme 0:227c21cd26be 244 TFT.locate(50, 10) ;
Rhyme 0:227c21cd26be 245 TFT.printf("Xtrinsic Accelerometer") ;
Rhyme 0:227c21cd26be 246 TFT.locate(90, 300) ;
Rhyme 0:227c21cd26be 247 TFT.printf("MMA8451Q") ;
Rhyme 0:227c21cd26be 248
Rhyme 0:227c21cd26be 249 prev[0] = xoffset + (signalHeight * clip((1.0 + acc->getAccX()))) ;
Rhyme 0:227c21cd26be 250 prev[1] = yoffset + (signalHeight * clip((1.0 + acc->getAccY()))) ;
Rhyme 0:227c21cd26be 251 prev[2] = zoffset + (signalHeight * clip((1.0 + acc->getAccZ()))) ;
Rhyme 0:227c21cd26be 252 pt = paneX[0] ;
Rhyme 0:227c21cd26be 253 backlight = 1 ;
Rhyme 0:227c21cd26be 254 for(t = 21 ; t < paneX[1] ; t++) {
Rhyme 0:227c21cd26be 255 data[0] = xoffset + (signalHeight * clip((1.0 + acc->getAccX()))) ;
Rhyme 0:227c21cd26be 256 data[1] = yoffset + (signalHeight * clip((1.0 + acc->getAccY()))) ;
Rhyme 0:227c21cd26be 257 data[2] = zoffset + (signalHeight * clip((1.0 + acc->getAccZ()))) ;
Rhyme 0:227c21cd26be 258 TFT.line(pt, prev[0], t, data[0], Red) ;
Rhyme 0:227c21cd26be 259 TFT.line(pt, prev[1], t, data[1], Green) ;
Rhyme 0:227c21cd26be 260 TFT.line(pt, prev[2], t, data[2], Yellow) ;
Rhyme 0:227c21cd26be 261 prev[0] = data[0] ;
Rhyme 0:227c21cd26be 262 prev[1] = data[1] ;
Rhyme 0:227c21cd26be 263 prev[2] = data[2] ;
Rhyme 0:227c21cd26be 264 pt = t ;
Rhyme 0:227c21cd26be 265 wait(0.01) ;
Rhyme 0:227c21cd26be 266 }
Rhyme 0:227c21cd26be 267 }
Rhyme 0:227c21cd26be 268
Rhyme 0:227c21cd26be 269 void incPage(void)
Rhyme 0:227c21cd26be 270 {
Rhyme 0:227c21cd26be 271 page++ ;
Rhyme 0:227c21cd26be 272 if (page >= numPage) {
Rhyme 0:227c21cd26be 273 page = 0 ;
Rhyme 0:227c21cd26be 274 }
Rhyme 0:227c21cd26be 275 }
Rhyme 0:227c21cd26be 276
Rhyme 0:227c21cd26be 277 void decPage(void)
Rhyme 0:227c21cd26be 278 {
Rhyme 0:227c21cd26be 279 page-- ;
Rhyme 0:227c21cd26be 280 if (page < 0) {
Rhyme 0:227c21cd26be 281 page = numPage - 1 ;
Rhyme 0:227c21cd26be 282 }
Rhyme 0:227c21cd26be 283 }
Rhyme 0:227c21cd26be 284
Rhyme 0:227c21cd26be 285 int main()
Rhyme 0:227c21cd26be 286 {
Rhyme 0:227c21cd26be 287 uint16_t x, y, z ;
Rhyme 0:227c21cd26be 288 int prevPage = 0 ;
Rhyme 0:227c21cd26be 289 int touched = 0 ;
Rhyme 0:227c21cd26be 290
Rhyme 0:227c21cd26be 291
Rhyme 0:227c21cd26be 292
Rhyme 0:227c21cd26be 293 initTFT() ;
Rhyme 0:227c21cd26be 294
Rhyme 0:227c21cd26be 295 screen1() ;
Rhyme 0:227c21cd26be 296
Rhyme 0:227c21cd26be 297 printf("Program Started!\n\r") ;
Rhyme 0:227c21cd26be 298
Rhyme 0:227c21cd26be 299 acc = new MMA8451Q(PTE25, PTE24, MMA8451_I2C_ADDRESS) ;
Rhyme 0:227c21cd26be 300
Rhyme 0:227c21cd26be 301 for(;;) {
Rhyme 0:227c21cd26be 302 // printf("TFT width = %d, height = %d\n\r", TFT.width(), TFT.height()) ;
Rhyme 0:227c21cd26be 303 switch(page) {
Rhyme 0:227c21cd26be 304 case 0:
Rhyme 0:227c21cd26be 305 if (prevPage != page) {
Rhyme 0:227c21cd26be 306 screen1() ;
Rhyme 0:227c21cd26be 307 }
Rhyme 0:227c21cd26be 308 wait(1) ;
Rhyme 0:227c21cd26be 309 break ;
Rhyme 0:227c21cd26be 310 case 1:
Rhyme 0:227c21cd26be 311 if (prevPage != page) {
Rhyme 0:227c21cd26be 312 screen2() ;
Rhyme 0:227c21cd26be 313 }
Rhyme 0:227c21cd26be 314 wait(1) ;
Rhyme 0:227c21cd26be 315 break ;
Rhyme 0:227c21cd26be 316 case 2:
Rhyme 0:227c21cd26be 317 if (prevPage != page) {
Rhyme 0:227c21cd26be 318 TFT.background(Black) ;
Rhyme 0:227c21cd26be 319 TFT.foreground(White) ;
Rhyme 0:227c21cd26be 320 TFT.cls() ;
Rhyme 0:227c21cd26be 321 }
Rhyme 0:227c21cd26be 322 screen3() ;
Rhyme 0:227c21cd26be 323 wait(2) ;
Rhyme 0:227c21cd26be 324 break ;
Rhyme 0:227c21cd26be 325 default:
Rhyme 0:227c21cd26be 326 page = 0 ;
Rhyme 0:227c21cd26be 327 break ;
Rhyme 0:227c21cd26be 328 }
Rhyme 0:227c21cd26be 329 prevPage = page ;
Rhyme 0:227c21cd26be 330 printf("Screen Printed\n\r") ;
Rhyme 0:227c21cd26be 331
Rhyme 0:227c21cd26be 332 x = 0 ; y = 0 ; z = 0 ;
Rhyme 0:227c21cd26be 333 touched = TSC.getRAWPoint(&x, &y, &z) ;
Rhyme 0:227c21cd26be 334 printf("touched = %d x = %d, y = %d, z = %d\n\r",touched, x,y,z) ;
Rhyme 0:227c21cd26be 335 if ((x != 0)||(y != 0) || (z != 0)) {
Rhyme 0:227c21cd26be 336 if (x < 1000) { // left
Rhyme 0:227c21cd26be 337 decPage() ;
Rhyme 0:227c21cd26be 338 } else if (x > 3000) { // right
Rhyme 0:227c21cd26be 339 incPage() ;
Rhyme 0:227c21cd26be 340 }
Rhyme 0:227c21cd26be 341 }
Rhyme 0:227c21cd26be 342 // wait(1) ;
Rhyme 0:227c21cd26be 343 }
Rhyme 0:227c21cd26be 344 }