/* ESP32 Touch Screen
Allows a user to touch the screen, displays a dot at that location
*/
#include <TFT_eSPI.h>
#include <SPI.h> // this is needed for display
#include <Wire.h> // this is needed for FT6206
#include <Adafruit_FT6206.h>
Adafruit_FT6206 ctp = Adafruit_FT6206();
// The display also uses hardware SPI, plus #9 & #10
#define TFT_CS 15
#define TFT_DC 2
#define TFT_MOSI 23
#define TFT_SCLK 18
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library with default width and height
void setup(void) {
Serial.begin(115200);
tft.begin();
if (! ctp.begin(40)) { // pass in 'sensitivity' coefficient
Serial.println("Couldn't start FT6206 touchscreen controller");
while (1);
}
tft.setRotation(0);
Serial.println("TFT set up");
String text = "Touch the screen to paint";
tft.drawString(text, 0, 0, 2);
}
void loop() {
if (ctp.touched()) {
// Retrieve a point
TS_Point p = ctp.getPoint();
p.x = map(p.x, 0, 240, 240, 0);
p.y = map(p.y, 0, 320, 320, 0);
tft.fillCircle(p.x, p.y, 2, TFT_WHITE);
Serial.print("x,y = ");
Serial.print(p.x);
Serial.print(",");
Serial.println(p.y);
}
}
Loading
ili9341-cap-touch
ili9341-cap-touch