projets de S3 s4 2021
Dependencies: mbed TFT_fonts SPI_TFT_ILI9341
Diff: main.cpp
- Revision:
- 1:33506fcfdd95
- Parent:
- 0:42ec9a44bc24
- Child:
- 2:fe018965e46c
diff -r 42ec9a44bc24 -r 33506fcfdd95 main.cpp --- a/main.cpp Mon Jan 07 06:40:27 2019 +0000 +++ b/main.cpp Mon Jan 07 16:15:52 2019 +0000 @@ -60,6 +60,44 @@ TouchScreen tft(PIN_XP, PIN_YP, PIN_XM, PIN_YM); //init TouchScreen port pins +struct point +{ + int x; + int y; + int z; +}; + +typedef struct point Point; + + +Point point(int xx, int yy, int zz){ + Point p; + p.x = xx; + p.y = yy; + p.z = zz; + return p; +} + +Point getPoint(){ + PinName _yp, _ym, _xm, _xp; + int z = 0; + int y2 = tft.readTouch(_xp,_xm,_yp,_ym); + int x2 = tft.readTouch(_yp,_ym,_xm,_xp); + int y1 = tft.readTouch(_xp,_xm,_ym,_yp); + int x1 = tft.readTouch(_yp,_ym,_xp,_xm); + int z2 = tft.readTouch(_ym,_xp,_yp,_xm); + int z1 = tft.readTouch(_ym,_xp,_xm,_yp); + + if (z1!=0){ + z = RXPLATE*x2/Q*(z2/z1-1); + }else{ + z = 0; + } + int x = x2; + int y = y2; + + return point(x,y,z); +} int main(){ @@ -79,16 +117,15 @@ while(1){ zz = zz + 1; // a point object holds x y and z coordinates. - //Point p = tft.getPoint(p); - Point c(100,120,25); + //Point p = getPoint(); //map the ADC value read to into pixel co-ordinates //p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); //p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); // we have some minimum pressure we consider 'valid' // pressure of 0 means no pressing! - TFT.locate(60,90); - printf("z = %d \r\n", c.x); + //TFT.locate(60,90); + //printf("z = %d \r\n", p.x); TFT.locate(60,120); printf("Initializing z...%d \r\n",zz); /*if (p.z > PRESSURE) {