Paint for the FRDM-KL25Z

Dependencies:   mbed TFT_fonts SPI_TFT_ILI9341

touch.cpp

Committer:
ecowboy
Date:
2019-01-10
Revision:
5:80791250acb2
Parent:
4:87b40e5986e7
Child:
6:13d0de9e679c

File content as of revision 5:80791250acb2:

#include "touch.h"
#include "mbed.h"
#include "stdio.h"


TouchScreen::TouchScreen(PinName xp, PinName yp, PinName xm, PinName ym) {
    }
    

int TouchScreen::readTouch(PinName a, PinName i, PinName n, PinName m){
    
    AnalogIn   _a(a);
    AnalogIn   _i(i);
    DigitalOut _n(n);
    DigitalOut _m(m);
    int y1=1;
    int y2=0;
    _n = 1;
    _m = 0;
    wait_us(50);
    //while(y1 != y2){
        y1 = _a.read_u16();
        wait_us(50);
        y2 = _a.read_u16();
        wait_us(50);
    //}
    _n=0;
    return (y1+y2)/2;
}



/*bool TouchScreen::isTouching(void){
    Point p = getPoint(p);
    if(p.z > PRESSURE)return 1;
    else return 0;
}*/

int map(float value, float fromSource, float toSource, float fromTarget, float toTarget){
        return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
}