jyghj
Dependencies: Images SeeedStudioTFTv2 TFT_fonts inclinometer mbed
Fork of Seeed_TFT_Touch_Shield by
Diff: main.cpp
- Revision:
- 5:d7868e4dc7d1
- Parent:
- 2:5c2f6ff36ff1
diff -r e98910e480b4 -r d7868e4dc7d1 main.cpp --- a/main.cpp Fri Feb 13 09:39:48 2015 +0000 +++ b/main.cpp Tue Apr 17 09:25:03 2018 +0000 @@ -26,75 +26,144 @@ #include "Arial24x23.h" #include "Arial28x28.h" #include "font_big.h" +#include "car.h" +#include "DFRobot_LIS2DH12.h" -#define PIN_XP A3 -#define PIN_XM A1 -#define PIN_YP A2 -#define PIN_YM A0 -#define PIN_MOSI D11 -#define PIN_MISO D12 -#define PIN_SCLK D13 -#define PIN_CS_TFT D5 -#define PIN_DC_TFT D6 -#define PIN_BL_TFT D7 -#define PIN_CS_SD D4 +#define PIN_XP p20 +#define PIN_XM p19 +#define PIN_YP p18 +#define PIN_YM p17 +#define PIN_MOSI p11 +#define PIN_MISO p12 +#define PIN_SCLK p13 +#define PIN_CS_TFT p14 +#define PIN_DC_TFT p21 +#define PIN_BL_TFT p15 +//#define PIN_CS_SD D4 + +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); + +// Serial connection between PC and MBED +Serial pc(USBTX, USBRX); +I2C i2c(p9, p10); +DFRobot_LIS2DH12 LIS(&i2c,&pc); + +point p; // creates pointer p.x,p.y + + +// sub-program +// this program will wait until user touches screen +// analog data of touch panel is converted trough ADC to digital value +// getTouch will store that value +//getPixel will then convert ADC value to 320*240 pixel coordinates +// this touch program will be used in every code at this example + +void touch() + { + while(1) + { + p.x=0;p.y=0; + if (TFT.getTouch(p)==TFT.YES) // read analog pos. + { + TFT.getTouch(p); + TFT.getPixel(p); // convert to pixel pos + pc.printf("\n\r Point x:%d, y:%d", p.x, p.y); // will print p.x and p.y valu to pc(putty/teraterm) + wait_ms(150); // give some time for the touch + break; + } + } + } -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); +void DFRobot_LIS2DH12::getIncline(int16_t &a, int16_t &b, int16_t &c) +{ + if((c > 900) && (c < 1100)&&(a > -250) && (a < 250)&&(b > -250) && (b < 250)) + { + TFT.printf("The sensor is level."); + } + else + { + TFT.printf("The sensor is tilted "); + if(a > 250) + { + TFT.printf("left"); + if(b > 250) + { + TFT.printf(" and backward."); + } + else if(b < -250) + { + TFT.printf(" and forward."); + } + else + { + TFT.printf("."); + } + } + else if(a < -250) + { + TFT.printf("right"); + if(b > 250) + { + TFT.printf(" and backward."); + } + else if(b < -250) + { + TFT.printf(" and forward."); + } + else + { + TFT.printf("."); + } + } + else + { + if(b > 250) + { + TFT.printf("backward."); + } + else if(b < -250) + { + TFT.printf("forward."); + } + else + { + TFT.printf("upside down."); + } + } + } + TFT.printf("\n\r"); +} int main() { - //Configure the display driver - TFT.background(Black); - TFT.foreground(White); - TFT.cls(); - - //Print a welcome message - TFT.set_font((unsigned char*) Arial12x12); - TFT.locate(0,0); - TFT.printf("Hello Mbed"); - - //Wait for 5 seconds - wait(5.0); - - //Draw some graphics - TFT.cls(); - TFT.set_font((unsigned char*) Arial24x23); - TFT.locate(100,100); - TFT.printf("Graphic"); - - TFT.line(0,0,100,0,Green); - TFT.line(0,0,0,200,Green); - TFT.line(0,0,100,200,Green); - - TFT.rect(100,50,150,100,Red); - TFT.fillrect(180,25,220,70,Blue); - - TFT.circle(80,150,33,White); - TFT.fillcircle(160,190,20,Yellow); - - double s; - for (int i = 0; i < 320; i++) { - s = 20 * sin((long double)i / 10); - TFT.pixel(i, 100 + (int)s, Red); + while(1) + { + + TFT.locate(0,0); // Set pixel location at screen + int counter=0; + //TFT initialize + TFT.claim(stdout); // send stdout to the TFT display + TFT.set_orientation(0); // set screen orientation to vertical + // TFT.set_orientation(1); // set screen orientation to horizontal + TFT.background(Black); // set background to black + TFT.foreground(White); // set chars to white + TFT.cls(); // clear the screen + TFT.set_font((unsigned char*) Arial12x12); // set used txt font + + while(LIS.init(LIS2DH12_RANGE_8GA) != 0) + { + TFT.printf("No I2C devices found\n\r"); + wait(1); + } + int16_t a, b, c; + + while (counter<12) + { + LIS.readXYZ(a, b, c); + LIS.mgScale(a, b, c); + LIS.getIncline(a,b,c); + wait(2); // wait 2 seconds + counter++; } - - //Wait for 5 seconds - wait(5.0); - - //Multiple fonts - TFT.foreground(White); - TFT.background(Blue); - TFT.cls(); - TFT.set_font((unsigned char*) Arial24x23); - TFT.locate(0,0); - TFT.printf("Different Fonts:"); - TFT.set_font((unsigned char*) Neu42x35); - TFT.locate(0,30); - TFT.printf("Hello Mbed 1"); - TFT.set_font((unsigned char*) Arial24x23); - TFT.locate(20,80); - TFT.printf("Hello Mbed 2"); - TFT.set_font((unsigned char*) Arial12x12); - TFT.locate(35,120); - TFT.printf("Hello Mbed 3"); + } }