Bodmer / TFT_Touch

Arduino touch screen library for XPT2046
27 stars 13 forks source link

TFT 7inch resistive SSD1963 and ESP32 Wroover Dev Kit1 #7

Open TangerineDreamer opened 2 years ago

TangerineDreamer commented 2 years ago

Hi bodmer, i've made some experimentations with my SSD1963 7inch,so i opened this topic because i didn't find anything on the net concerning SSD1963 7 inch with e_SPI and TFT_Touch. I didn't know here to post it os i did here,delete it if you think it's not the place.

TangerineDreamer commented 2 years ago

Here my sketch to test touch buttons:

//Button test with SSD1963 - 7INCH Resistive & ESP32 Wroover Dev Kit 1

            //800x480 in TFT_Touch.cpp :  _hres = 800  &  _vres = 480

include

include

TFT_eSPI tft = TFT_eSPI();

// Call up touch screen library

include

// These are the pins used to interface between the 2046 touch controller and Arduino Pro

define DOUT 19 / Data out pin (T_DO) of touch screen /

define DIN 23 / Data in pin (T_DIN) of touch screen /

define DCS 20 / Chip select pin (T_CS) of touch screen /

define DCLK 18 / Clock pin (T_CLK) of touch screen /

/ Create an instance of the touch screen library / TFT_Touch touch = TFT_Touch(DCS, DCLK, DIN, DOUT);

void setup() { Serial.begin(115200);

tft.init();

// Set the TFT and touch screen to landscape orientation tft.setRotation(1); touch.setRotation(1);

tft.fillScreen(TFT_BLACK);

// TFT H_MAX = 800 & TFT V_MAX = 480 //tft.fillRect(X_MIN, V_MAX - Y_MAX, X_MAX, Y_MAX, COLOR);//Only if Y coarse Inverted in rotation(1) !!

tft.fillRect(400, 240, 400,240, TFT_WHITE);//half screen calibration test

//-------------BUTTONS--------------- tft.fillRect(0, 380, 100, 100, TFT_RED); tft.fillRect(100, 380, 100, 100, TFT_BLUE); tft.fillRect(200, 380, 100, 100, TFT_GREEN); tft.fillRect(300, 380, 100, 100, TFT_YELLOW);

}

void loop() { //int X_RawData; //int Y_RawData; int X_Coord; int Y_Coord; int X_RAW; int Y_RAW;

// Check if the touch screen is currently pressed // Raw and coordinate values are stored within library at this instant // for later retrieval by GetRaw and GetCoord functions.

if (touch.Pressed()) // Note this function updates coordinates stored within library variables { // Read the current X and Y axis as Raw co-ordinates at the last touch time // The values were captured when Pressed() was called!

//Raw coordonates with 800x480 in TFT_Touch.cpp------------
X_RAW = touch.X()- 100;
Y_RAW = 170 - touch.Y()+ 180;//Y coarse inverted corrections

//Remap X & Y Raw datas to fit the TFT resolution 
X_Coord = map(X_RAW,0,530,0,800);
Y_Coord = map(Y_RAW,0,220,0,480);

//Debug Raw datas & coordonates in the monitor 
Serial.println("X_RAW,Y_RAW :");
Serial.print(X_RAW); Serial.print(","); Serial.println(Y_RAW);
Serial.println("X_Coord,Y_Coord :");
Serial.print(X_Coord); Serial.print(","); Serial.println(Y_Coord);
Serial.println();

//Button test verification on the monitor
if(X_Coord>400 && X_Coord<800 && Y_Coord>25 && Y_Coord<240)
Serial.println("WHITE PRESSED!");
if(X_Coord>35 && X_Coord<135 && Y_Coord>25 && Y_Coord<100)
Serial.println("RED PRESSED!");
if(X_Coord>135 && X_Coord<235 && Y_Coord>25 && Y_Coord<100)
Serial.println("BLUE PRESSED!");
if(X_Coord>235 && X_Coord<335 && Y_Coord>25 && Y_Coord<100)
Serial.println("GREEN PRESSED!");
if(X_Coord>335 && X_Coord<435 && Y_Coord>25 && Y_Coord<100)
Serial.println("YELLOW PRESSED!");

} }