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:
Wed Jun 03 02:06:49 2015 +0000
Revision:
3:5b9647f22941
Parent:
1:5ea1dc8f875f
PIN_CS_TSC is changed to PTC12 for boards E or later.; For earlier boards please use PTA0.

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 3:5b9647f22941 71 // for board rev E or later
Rhyme 3:5b9647f22941 72 #define PIN_CS_TSC PTC12
Rhyme 3:5b9647f22941 73 // for earlier boards use following line
Rhyme 3:5b9647f22941 74 // #define PIN_CS_TSC PTA0
Rhyme 0:227c21cd26be 75 #define PIN_TSC_INTR PTC3
Rhyme 0:227c21cd26be 76 #define PIN_BACKLIGHT PTA1
Rhyme 0:227c21cd26be 77 #endif
Rhyme 0:227c21cd26be 78
Rhyme 0:227c21cd26be 79
Rhyme 0:227c21cd26be 80 #define MMA8451_I2C_ADDRESS (0x1d<<1)
Rhyme 0:227c21cd26be 81 MMA8451Q *acc = 0 ;
Rhyme 0:227c21cd26be 82
Rhyme 0:227c21cd26be 83 // 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 84 // SPI_TFT_ILI9341(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName dc, const char* name ="TFT");
Rhyme 0:227c21cd26be 85 SPI_TFT_ILI9341 TFT(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_BL_TFT, PIN_DC_TFT) ;
Rhyme 0:227c21cd26be 86 SPI_STMPE610 TSC(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ;
Rhyme 0:227c21cd26be 87
Rhyme 0:227c21cd26be 88 DigitalOut backlight(PIN_BACKLIGHT) ;
Rhyme 0:227c21cd26be 89 DigitalIn pinD7(PIN_TSC_INTR) ;
Rhyme 0:227c21cd26be 90
Rhyme 0:227c21cd26be 91 int page = 0 ;
Rhyme 0:227c21cd26be 92 int numPage = 3 ;
Rhyme 0:227c21cd26be 93
Rhyme 0:227c21cd26be 94 void initTFT(void)
Rhyme 0:227c21cd26be 95 {
Rhyme 0:227c21cd26be 96 //Configure the display driver
Rhyme 0:227c21cd26be 97 TFT.background(Black);
Rhyme 0:227c21cd26be 98 TFT.foreground(White);
Rhyme 0:227c21cd26be 99 wait(0.01) ;
Rhyme 0:227c21cd26be 100 TFT.cls();
Rhyme 0:227c21cd26be 101 }
Rhyme 0:227c21cd26be 102
Rhyme 0:227c21cd26be 103 void screen1(void) // Welcome Screen
Rhyme 0:227c21cd26be 104 {
Rhyme 0:227c21cd26be 105 backlight = 0 ;
Rhyme 0:227c21cd26be 106 TFT.background(White) ;
Rhyme 0:227c21cd26be 107 TFT.cls() ;
Rhyme 0:227c21cd26be 108
Rhyme 0:227c21cd26be 109 wait(0.1) ;
Rhyme 0:227c21cd26be 110 TFT.set_font((unsigned char*) Arial24x23);
Rhyme 0:227c21cd26be 111 TFT.foreground(Red) ;
Rhyme 0:227c21cd26be 112 TFT.locate(80, 40) ;
Rhyme 0:227c21cd26be 113 TFT.printf("mbed") ;
Rhyme 0:227c21cd26be 114 TFT.foreground(Blue);
Rhyme 0:227c21cd26be 115 TFT.locate(60, 80) ;
Rhyme 0:227c21cd26be 116 TFT.printf("TFT 2.8\"") ;
Rhyme 0:227c21cd26be 117 TFT.locate(40, 120) ;
Rhyme 0:227c21cd26be 118 TFT.printf("with touch") ;
Rhyme 0:227c21cd26be 119 TFT.foreground(Black);
Rhyme 0:227c21cd26be 120 TFT.set_font((unsigned char*) Arial12x12);
Rhyme 0:227c21cd26be 121 TFT.foreground(Blue) ;
Rhyme 0:227c21cd26be 122 TFT.locate(10, 180) ;
Rhyme 0:227c21cd26be 123 TFT.printf("This program is running on") ;
Rhyme 0:227c21cd26be 124 TFT.locate(10, 200) ;
Rhyme 0:227c21cd26be 125 TFT.printf("freescale FRDM-K64F with") ;
Rhyme 0:227c21cd26be 126 TFT.locate(10, 220) ;
Rhyme 0:227c21cd26be 127 TFT.printf("a program developed on mbed") ;
Rhyme 0:227c21cd26be 128 TFT.foreground(Green) ;
Rhyme 0:227c21cd26be 129 TFT.locate(10, 260) ;
Rhyme 0:227c21cd26be 130 TFT.printf("To advance demo page, touch") ;
Rhyme 0:227c21cd26be 131 TFT.locate(10, 280) ;
Rhyme 0:227c21cd26be 132 TFT.printf("and hold right side of screen") ;
Rhyme 0:227c21cd26be 133 TFT.locate(10, 300) ;
Rhyme 0:227c21cd26be 134 TFT.printf("until the next screen starts") ;
Rhyme 0:227c21cd26be 135 backlight = 1 ;
Rhyme 0:227c21cd26be 136 }
Rhyme 0:227c21cd26be 137
Rhyme 0:227c21cd26be 138 void screen2(void) // Graphics
Rhyme 0:227c21cd26be 139 {
Rhyme 0:227c21cd26be 140 //Draw some graphics
Rhyme 0:227c21cd26be 141 int i, x[2], y[2] ;
Rhyme 0:227c21cd26be 142 backlight = 0 ;
Rhyme 0:227c21cd26be 143
Rhyme 0:227c21cd26be 144 TFT.background(Black);
Rhyme 0:227c21cd26be 145 TFT.foreground(White);
Rhyme 0:227c21cd26be 146 TFT.cls() ;
Rhyme 0:227c21cd26be 147 TFT.set_font((unsigned char*) Arial12x12);
Rhyme 0:227c21cd26be 148 TFT.locate(90,0);
Rhyme 0:227c21cd26be 149 TFT.printf("Graphics");
Rhyme 0:227c21cd26be 150
Rhyme 0:227c21cd26be 151 x[0] = 25 ; x[1] = 224 ;
Rhyme 0:227c21cd26be 152 y[0] = 20 ; y[1] = 219 ;
Rhyme 0:227c21cd26be 153 for (i = 20 ; i < 220 ; i += 10) {
Rhyme 0:227c21cd26be 154 TFT.line(i+5, y[0], i+5, y[1], Blue) ;
Rhyme 0:227c21cd26be 155 TFT.line(x[0], i, x[1], i, Blue) ;
Rhyme 0:227c21cd26be 156 }
Rhyme 0:227c21cd26be 157 TFT.line(125, y[0], 125, y[1], Green) ;
Rhyme 0:227c21cd26be 158 TFT.line(x[0], 120, x[1], 120, Green) ;
Rhyme 0:227c21cd26be 159 TFT.rect(x[0],y[0], x[1], y[1], Green) ;
Rhyme 0:227c21cd26be 160 TFT.locate(10, 20) ;
Rhyme 0:227c21cd26be 161 TFT.printf("V") ;
Rhyme 0:227c21cd26be 162 TFT.locate(0, 115) ;
Rhyme 0:227c21cd26be 163 TFT.printf("0.0") ;
Rhyme 0:227c21cd26be 164 TFT.locate(115, 225) ;
Rhyme 0:227c21cd26be 165 TFT.printf("0.0") ;
Rhyme 0:227c21cd26be 166 TFT.locate(215, 225) ;
Rhyme 0:227c21cd26be 167 TFT.printf("T") ;
Rhyme 0:227c21cd26be 168
Rhyme 0:227c21cd26be 169 double s;
Rhyme 0:227c21cd26be 170 for (int i = x[0]; i < 225; i++) {
Rhyme 0:227c21cd26be 171 s = 40 * sin((long double)i / 20);
Rhyme 0:227c21cd26be 172 TFT.pixel(i, 120 + (int)s, White);
Rhyme 0:227c21cd26be 173 }
Rhyme 0:227c21cd26be 174
Rhyme 0:227c21cd26be 175 TFT.fillrect(10, 240, 229, 309, White) ;
Rhyme 0:227c21cd26be 176 TFT.rect(10, 240, 229, 309, Red) ;
Rhyme 0:227c21cd26be 177 TFT.rect(11, 241, 228, 308, Red) ;
Rhyme 0:227c21cd26be 178
Rhyme 0:227c21cd26be 179 TFT.background(White) ;
Rhyme 0:227c21cd26be 180 TFT.foreground(Black) ;
Rhyme 0:227c21cd26be 181 TFT.locate(20, 250) ;
Rhyme 0:227c21cd26be 182 TFT.printf("With QVGA resolution") ;
Rhyme 0:227c21cd26be 183 TFT.locate(20, 270) ;
Rhyme 0:227c21cd26be 184 TFT.printf("simple graphics drawing") ;
Rhyme 0:227c21cd26be 185 TFT.locate(20, 290) ;
Rhyme 0:227c21cd26be 186 TFT.printf("capability is provided") ;
Rhyme 0:227c21cd26be 187 backlight = 1 ;
Rhyme 0:227c21cd26be 188 }
Rhyme 0:227c21cd26be 189
Rhyme 0:227c21cd26be 190 double clip(double src)
Rhyme 0:227c21cd26be 191 {
Rhyme 0:227c21cd26be 192 double value ;
Rhyme 0:227c21cd26be 193 value = src ;
Rhyme 0:227c21cd26be 194 if (value < 0.0) {
Rhyme 0:227c21cd26be 195 value = 0.0 ;
Rhyme 0:227c21cd26be 196 } else if (value > 2.0) {
Rhyme 0:227c21cd26be 197 value = 2.0 ;
Rhyme 0:227c21cd26be 198 }
Rhyme 0:227c21cd26be 199 return( value ) ;
Rhyme 0:227c21cd26be 200 }
Rhyme 0:227c21cd26be 201
Rhyme 0:227c21cd26be 202 void screen3(void)
Rhyme 0:227c21cd26be 203 {
Rhyme 0:227c21cd26be 204 int t = 0 ;
Rhyme 0:227c21cd26be 205 int pt = 0 ; // previous t
Rhyme 0:227c21cd26be 206 int i, x, y ;
Rhyme 0:227c21cd26be 207 unsigned int data[3] ; // for x, y, z
Rhyme 0:227c21cd26be 208 unsigned int prev[3] ;
Rhyme 0:227c21cd26be 209 unsigned short signalHeight = 39 ;
Rhyme 0:227c21cd26be 210 unsigned short xoffset = 30 ;
Rhyme 0:227c21cd26be 211 unsigned short yoffset = 120 ;
Rhyme 0:227c21cd26be 212 unsigned short zoffset = 210 ;
Rhyme 0:227c21cd26be 213 unsigned short paneX[2] = {20, 235} ;
Rhyme 0:227c21cd26be 214 unsigned short paneH = 81 ;
Rhyme 0:227c21cd26be 215
Rhyme 0:227c21cd26be 216 backlight = 0 ;
Rhyme 0:227c21cd26be 217 TFT.background(Black) ;
Rhyme 0:227c21cd26be 218 TFT.foreground(White) ;
Rhyme 0:227c21cd26be 219 // TFT.cls() ;
Rhyme 0:227c21cd26be 220
Rhyme 0:227c21cd26be 221
Rhyme 0:227c21cd26be 222 TFT.fillrect(paneX[0], xoffset, paneX[1], xoffset+paneH, Black) ;
Rhyme 0:227c21cd26be 223 TFT.fillrect(paneX[0], yoffset, paneX[1], yoffset+paneH, Black) ;
Rhyme 0:227c21cd26be 224 TFT.fillrect(paneX[0], zoffset, paneX[1], zoffset+paneH, Black) ;
Rhyme 0:227c21cd26be 225 TFT.fillrect(paneX[0], xoffset, paneX[1], xoffset+paneH, Black) ;
Rhyme 0:227c21cd26be 226 for (i = 0 ; i < 10 ; i++ ) {
Rhyme 0:227c21cd26be 227 y = i * 8 ;
Rhyme 0:227c21cd26be 228 TFT.line(paneX[0], xoffset + y, paneX[1], xoffset + y, Blue) ;
Rhyme 0:227c21cd26be 229 TFT.line(paneX[0], yoffset + y, paneX[1], yoffset + y, Blue) ;
Rhyme 0:227c21cd26be 230 TFT.line(paneX[0], zoffset + y, paneX[1], zoffset + y, Blue) ;
Rhyme 0:227c21cd26be 231 }
Rhyme 0:227c21cd26be 232 for (x = 30 ; x < paneX[1] ; x += 10 ) {
Rhyme 0:227c21cd26be 233 TFT.line(x, xoffset, x, xoffset+paneH, Blue) ;
Rhyme 0:227c21cd26be 234 TFT.line(x, yoffset, x, yoffset+paneH, Blue) ;
Rhyme 0:227c21cd26be 235 TFT.line(x, zoffset, x, zoffset+paneH, Blue) ;
Rhyme 0:227c21cd26be 236 }
Rhyme 0:227c21cd26be 237 TFT.rect(paneX[0], xoffset, paneX[1], xoffset+paneH, White) ;
Rhyme 0:227c21cd26be 238 TFT.rect(paneX[0], yoffset, paneX[1], yoffset+paneH, White) ;
Rhyme 0:227c21cd26be 239 TFT.rect(paneX[0], zoffset, paneX[1], zoffset+paneH, White) ;
Rhyme 0:227c21cd26be 240 TFT.set_font((unsigned char*) Arial12x12);
Rhyme 0:227c21cd26be 241 TFT.locate(5, xoffset+30) ;
Rhyme 0:227c21cd26be 242 TFT.printf("X") ;
Rhyme 0:227c21cd26be 243 TFT.locate(5, yoffset+30) ;
Rhyme 0:227c21cd26be 244 TFT.printf("Y") ;
Rhyme 0:227c21cd26be 245 TFT.locate(5, zoffset+30) ;
Rhyme 0:227c21cd26be 246 TFT.printf("Z") ;
Rhyme 0:227c21cd26be 247 TFT.locate(50, 10) ;
Rhyme 0:227c21cd26be 248 TFT.printf("Xtrinsic Accelerometer") ;
Rhyme 0:227c21cd26be 249 TFT.locate(90, 300) ;
Rhyme 0:227c21cd26be 250 TFT.printf("MMA8451Q") ;
Rhyme 0:227c21cd26be 251
Rhyme 0:227c21cd26be 252 prev[0] = xoffset + (signalHeight * clip((1.0 + acc->getAccX()))) ;
Rhyme 0:227c21cd26be 253 prev[1] = yoffset + (signalHeight * clip((1.0 + acc->getAccY()))) ;
Rhyme 0:227c21cd26be 254 prev[2] = zoffset + (signalHeight * clip((1.0 + acc->getAccZ()))) ;
Rhyme 0:227c21cd26be 255 pt = paneX[0] ;
Rhyme 0:227c21cd26be 256 backlight = 1 ;
Rhyme 0:227c21cd26be 257 for(t = 21 ; t < paneX[1] ; t++) {
Rhyme 0:227c21cd26be 258 data[0] = xoffset + (signalHeight * clip((1.0 + acc->getAccX()))) ;
Rhyme 0:227c21cd26be 259 data[1] = yoffset + (signalHeight * clip((1.0 + acc->getAccY()))) ;
Rhyme 0:227c21cd26be 260 data[2] = zoffset + (signalHeight * clip((1.0 + acc->getAccZ()))) ;
Rhyme 0:227c21cd26be 261 TFT.line(pt, prev[0], t, data[0], Red) ;
Rhyme 0:227c21cd26be 262 TFT.line(pt, prev[1], t, data[1], Green) ;
Rhyme 0:227c21cd26be 263 TFT.line(pt, prev[2], t, data[2], Yellow) ;
Rhyme 0:227c21cd26be 264 prev[0] = data[0] ;
Rhyme 0:227c21cd26be 265 prev[1] = data[1] ;
Rhyme 0:227c21cd26be 266 prev[2] = data[2] ;
Rhyme 0:227c21cd26be 267 pt = t ;
Rhyme 0:227c21cd26be 268 wait(0.01) ;
Rhyme 0:227c21cd26be 269 }
Rhyme 0:227c21cd26be 270 }
Rhyme 0:227c21cd26be 271
Rhyme 0:227c21cd26be 272 void incPage(void)
Rhyme 0:227c21cd26be 273 {
Rhyme 0:227c21cd26be 274 page++ ;
Rhyme 0:227c21cd26be 275 if (page >= numPage) {
Rhyme 0:227c21cd26be 276 page = 0 ;
Rhyme 0:227c21cd26be 277 }
Rhyme 0:227c21cd26be 278 }
Rhyme 0:227c21cd26be 279
Rhyme 0:227c21cd26be 280 void decPage(void)
Rhyme 0:227c21cd26be 281 {
Rhyme 0:227c21cd26be 282 page-- ;
Rhyme 0:227c21cd26be 283 if (page < 0) {
Rhyme 0:227c21cd26be 284 page = numPage - 1 ;
Rhyme 0:227c21cd26be 285 }
Rhyme 0:227c21cd26be 286 }
Rhyme 0:227c21cd26be 287
Rhyme 0:227c21cd26be 288 int main()
Rhyme 0:227c21cd26be 289 {
Rhyme 0:227c21cd26be 290 uint16_t x, y, z ;
Rhyme 0:227c21cd26be 291 int prevPage = 0 ;
Rhyme 0:227c21cd26be 292 int touched = 0 ;
Rhyme 0:227c21cd26be 293
Rhyme 0:227c21cd26be 294
Rhyme 0:227c21cd26be 295
Rhyme 0:227c21cd26be 296 initTFT() ;
Rhyme 0:227c21cd26be 297
Rhyme 0:227c21cd26be 298 screen1() ;
Rhyme 0:227c21cd26be 299
Rhyme 0:227c21cd26be 300 printf("Program Started!\n\r") ;
Rhyme 0:227c21cd26be 301
Rhyme 0:227c21cd26be 302 acc = new MMA8451Q(PTE25, PTE24, MMA8451_I2C_ADDRESS) ;
Rhyme 0:227c21cd26be 303
Rhyme 0:227c21cd26be 304 for(;;) {
Rhyme 0:227c21cd26be 305 // printf("TFT width = %d, height = %d\n\r", TFT.width(), TFT.height()) ;
Rhyme 0:227c21cd26be 306 switch(page) {
Rhyme 0:227c21cd26be 307 case 0:
Rhyme 0:227c21cd26be 308 if (prevPage != page) {
Rhyme 0:227c21cd26be 309 screen1() ;
Rhyme 0:227c21cd26be 310 }
Rhyme 0:227c21cd26be 311 wait(1) ;
Rhyme 0:227c21cd26be 312 break ;
Rhyme 0:227c21cd26be 313 case 1:
Rhyme 0:227c21cd26be 314 if (prevPage != page) {
Rhyme 0:227c21cd26be 315 screen2() ;
Rhyme 0:227c21cd26be 316 }
Rhyme 0:227c21cd26be 317 wait(1) ;
Rhyme 0:227c21cd26be 318 break ;
Rhyme 0:227c21cd26be 319 case 2:
Rhyme 0:227c21cd26be 320 if (prevPage != page) {
Rhyme 0:227c21cd26be 321 TFT.background(Black) ;
Rhyme 0:227c21cd26be 322 TFT.foreground(White) ;
Rhyme 0:227c21cd26be 323 TFT.cls() ;
Rhyme 0:227c21cd26be 324 }
Rhyme 0:227c21cd26be 325 screen3() ;
Rhyme 0:227c21cd26be 326 wait(2) ;
Rhyme 0:227c21cd26be 327 break ;
Rhyme 0:227c21cd26be 328 default:
Rhyme 0:227c21cd26be 329 page = 0 ;
Rhyme 0:227c21cd26be 330 break ;
Rhyme 0:227c21cd26be 331 }
Rhyme 0:227c21cd26be 332 prevPage = page ;
Rhyme 0:227c21cd26be 333 printf("Screen Printed\n\r") ;
Rhyme 0:227c21cd26be 334
Rhyme 0:227c21cd26be 335 x = 0 ; y = 0 ; z = 0 ;
Rhyme 0:227c21cd26be 336 touched = TSC.getRAWPoint(&x, &y, &z) ;
Rhyme 0:227c21cd26be 337 printf("touched = %d x = %d, y = %d, z = %d\n\r",touched, x,y,z) ;
Rhyme 0:227c21cd26be 338 if ((x != 0)||(y != 0) || (z != 0)) {
Rhyme 0:227c21cd26be 339 if (x < 1000) { // left
Rhyme 0:227c21cd26be 340 decPage() ;
Rhyme 0:227c21cd26be 341 } else if (x > 3000) { // right
Rhyme 0:227c21cd26be 342 incPage() ;
Rhyme 0:227c21cd26be 343 }
Rhyme 0:227c21cd26be 344 }
Rhyme 0:227c21cd26be 345 // wait(1) ;
Rhyme 0:227c21cd26be 346 }
Rhyme 0:227c21cd26be 347 }