#include <Adafruit_GFX.h> // Biblioteca para gráficos
#include <Adafruit_ILI9341.h> // Biblioteca para o ILI9341
#include <TouchScreen.h> // Biblioteca para touch
// Definições para a tela LCD ILI9341
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// Definições para o Touch Screen
#define YP A3 // Pino Y+
#define XM A2 // Pino X-
#define YM 9 // Pino Y-
#define XP 8 // Pino X+
// Calibração do touch (depende do modelo da tela)
#define TS_MINX 150
#define TS_MAXX 920
#define TS_MINY 120
#define TS_MAXY 940
#define MINPRESSURE 10
#define MAXPRESSURE 1000
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
void setup() {
Serial.begin(9600);
// Inicializa a tela LCD
tft.begin();
tft.setRotation(1); // Define a orientação da tela
tft.fillScreen(ILI9341_BLACK); // Preenche com fundo preto
// Exibe texto inicial
tft.setTextSize(2);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(10, 10);
tft.print("Touch Screen Demo");
}
void loop() {
// Lê o ponto de toque
TSPoint p = ts.getPoint();
// Verifica se houve toque
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
// Converte as coordenadas para o tamanho da tela
int x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
int y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
// Exibe coordenadas no Serial Monitor
Serial.print("Toque detectado em: ");
Serial.print("X = ");
Serial.print(x);
Serial.print(", Y = ");
Serial.println(y);
// Desenha um círculo no local do toque
tft.fillCircle(x, y, 5, ILI9341_RED);
}
delay(50); // Pequeno atraso para evitar múltiplas leituras
}
Loading
ili9341-cap-touch
ili9341-cap-touch