#include #include "TouchScreen.h" #include #define LCD_CS A3 // Chip Select goes to Analog 3 #define LCD_CD A2 // Command/Data goes to Analog 2 #define LCD_WR A1 // LCD Write goes to Analog 1 #define LCD_RD A0 // LCD Read goes to Analog 0 #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin #define YP A2 // must be an analog pin, use "An" notation! #define XM A3 // must be an analog pin, use "An" notation! #define YM 8 // can be a digital pin #define XP 9 // can be a digital pin #define TS_MINX 129 // X Min Value (Raw) #define TS_MAXX 954 // X Max Value (Raw) #define TS_MINY 104 // Y Min Value (Raw) #define TS_MAXY 954 // Y Max Value (Raw) Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); void setup(void) { Serial.begin(115200); } void loop(void) { TSPoint p = ts.getPoint(); if (p.z > ts.pressureThreshhold) { Serial.print("("); Serial.print(adjust_x(p.x)); Serial.print(','); Serial.print(adjust_y(p.y)); Serial.print(")"); Serial.print("\tX = "); Serial.print(p.x); Serial.print("\tY = "); Serial.print(p.y); Serial.print("\tPressure = "); Serial.println(p.z); } delay(100); } int adjust_x(int x) { int TFT_MAX = tft.width() - 1; return constrain(map(x, TS_MINX, TS_MAXX, 0, TFT_MAX), 0, TFT_MAX); } int adjust_y(int y) { int TFT_MAX = tft.height() - 1; return constrain(map(y, TS_MINY, TS_MAXY, 0, TFT_MAX), 0, TFT_MAX); }