LIB for resistiv touchscreen connected to 4 mbed pins Use SPI_TFT lib

Dependents:   touch LCD_Grapher Mandelbrot Tactile ... more

Embed: (wiki syntax)

« Back to documentation index

touch_tft Class Reference

touch_tft Class Reference

touchscreen control class, based on SPI_TFT More...

#include <touch_tft.h>

Public Member Functions

 touch_tft (PinName xp, PinName xm, PinName yp, PinName ym, PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, const char *name="TFT")
 create a TFT with touch object connected to the pins:
void calibrate (void)
 calibrate the touch display
point get_touch (void)
 read x and y analog samples
point to_pixel (point a_point)
 calculate coord on screen
bool is_touched (point a)
 test if screen is touched

Detailed Description

touchscreen control class, based on SPI_TFT

Example:

 #include "mbed.h"
 #include "SPI_TFT.h"
 #include "Arial12x12.h"
 #include "Arial28x28.h"
 #include "touch_tft.h"
 // the TFT is connected to SPI pin 5-7
 // the touch is connected to 19,20,16,17

 touch_tft tt(p19,p20,p16,p17,p5, p6, p7, p8, p15,"TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset

 int main() {
 point p;

  tt.claim(stdout);        // send stdout to the TFT display
  tt.background(Black);    // set background to black
  tt.foreground(White);    // set chars to white
  tt.cls();                // clear the screen
  tt.set_font((unsigned char*) Arial12x12);  // select the font
  tt.set_orientation(1);

  tt.calibrate();          // calibrate the touch
 while (1) {
       p = tt.get_touch();   // read analog pos.
       if (tt.is_touched(p)) {  // test if touched
           p = tt.to_pixel(p);             // convert to pixel pos
           tt.fillcircle(p.x,p.y,3,Blue);  // print a blue dot on the screen
     }
 }

Definition at line 61 of file touch_tft.h.


Constructor & Destructor Documentation

touch_tft ( PinName  xp,
PinName  xm,
PinName  yp,
PinName  ym,
PinName  mosi,
PinName  miso,
PinName  sclk,
PinName  cs,
PinName  reset,
const char *  name = "TFT" 
)

create a TFT with touch object connected to the pins:

Parameters:
pinxp resistiv touch x+
pinxm resistiv touch x-
pinyp resistiv touch y+
pinym resistiv touch y-
mosi,miso,sclkSPI connection to TFT
cspin connected to CS of display
resetpin connected to RESET of display based on my SPI_TFT lib

Definition at line 21 of file touch_tft.cpp.


Member Function Documentation

void calibrate ( void   )

calibrate the touch display

User is asked to touch on two points on the screen

Definition at line 110 of file touch_tft.cpp.

point get_touch ( void   )

read x and y analog samples

Returns:
point(x,y)

Definition at line 30 of file touch_tft.cpp.

bool is_touched ( point  a )

test if screen is touched

Parameters:
pointanalog x,y
Returns:
true is touched

Definition at line 191 of file touch_tft.cpp.

point to_pixel ( point  a_point )

calculate coord on screen

Parameters:
a_pointpoint(analog x, analog y)
Returns:
point(pixel x, pixel y)

Definition at line 181 of file touch_tft.cpp.