LIB for resistiv touchscreen connected to 4 mbed pins Use SPI_TFT lib
Fork of Touch_tft by
Diff: touch_tft.cpp
- Revision:
- 3:1c2df48aa2eb
- Parent:
- 2:ef7972c29c0e
- Child:
- 4:330f2f16dabb
--- a/touch_tft.cpp Sun Sep 04 21:23:31 2011 +0000 +++ b/touch_tft.cpp Wed Jun 26 21:20:30 2013 +0000 @@ -23,46 +23,63 @@ _xp(xp),_xm(xm),_yp(yp),_ym(ym),_ax(xp),_ay(yp), SPI_TFT(mosi,miso,sclk,cs,reset,name) { xa = xp; + xb = xm; ya = yp; + yb = ym; } +char Buffer[30]; point touch_tft::get_touch() { unsigned short x1 = 0,x2 = 0, y1 = 0, y2 = 0; - unsigned int s1 = 0,s2 = 0,d1 , d2; + int s1 = 0,s2 = 0,d1 , d2; point p; do { // read y voltage +// DigitalOut __xp(xa); _xp.output(); +// DigitalOut __xm(xb); _xm.output(); switch (orientation) { case(0): case(3): _xp = 1; _xm = 0; +// __xp = 1; +// __xm = 0; break; case(1): case(2): _xp = 0; _xm = 1; +// __xp = 0; +// __xm = 1; break; } +// DigitalIn __ym(yb); +// __ym.mode(PullNone); _ym.input(); // y- have to be passive + _ym.mode(PullNone); AnalogIn Ay(ya); // we have to call the constructor to switch to analog mode wait_us(10); y1 = Ay.read_u16(); // get y voltage + y1 = Ay.read_u16(); d1 = (y1 > y2)? (y1-y2) : (y2-y1); - if (((y1 < 8000) && (d1 < 2000)) || ((y1 > 8000) && (d1 < 150))) s1 ++; + if (((y1 < 8000) && (d1 < 2000)) || ((y1 > 8000) && (d1 < 250))) s1 ++; else { if (s1 > 0) s1 --; } + // debug + locate(1,7); +// sprintf(Buffer, "d: %4d y: %5d s1: %4d",d1,y1,s1); + sprintf(Buffer, "d: %5d y1: %5d y2: %5d s1: %5d",d1,y1,y2,s1); + printf(Buffer); y2 = y1; - // debug - //locate(1,7); - //printf("d: %4d y: %5d s1: %4d",d1,y1,s1); - + // read x voltage +// DigitalOut __yp(ya); +// DigitalOut __ym1(yb); _yp.output(); _ym.output(); switch (orientation) { @@ -70,26 +87,35 @@ case(1): _yp = 1; _ym = 0; +// __yp = 1; +// __ym1 = 0; break; case(2): case(3): _yp = 0; _ym = 1; +// __yp = 0; +// __ym1 = 1; break; } +// DigitalIn __ixm(xb); _xm.input(); // x- have to be passive +// _xm.mode(PullNone); AnalogIn Ax(xa); // we have to call the constructor to switch to analog mode wait_us(10); x1 = Ax.read_u16(); // get x voltage + x1 = Ax.read_u16(); d2 = (x1 > x2)? (x1-x2) : (x2-x1); - if (((x1 < 8000) && (d2 < 2000)) || ((x1 > 8000) && (d2 < 150))) s2 ++; + if (((x1 < 8000) && (d2 < 2000)) || ((x1 > 8000) && (d2 < 250))) s2 ++; else { if (s2 > 0) s2 --; } x2 = x1; // debug - //locate(1,8); - //printf("d: %4d x: %5d s2: %4d",d2,x1,s2); + locate(1,20); + sprintf(Buffer, "d: %5d x1: %5d x2: %5d s1: %4d",d2,x1,x2, s2); + printf(Buffer); + //printf("d: %4d x: %5d s2: %4d",d2,x1,s2); } while (s1 < 3 || s2 < 3); // read until we have three samples close together switch (orientation) {