#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_FT6206.h>
// กำหนดขาของจอ ILI9341
#define TFT_CS 5
#define TFT_DC 2
#define TFT_RST 4
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
Adafruit_FT6206 ctp = Adafruit_FT6206(); // ใช้ I2C (SDA, SCL)
void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(3);
if (!ctp.begin(40)) {
Serial.println("Capacitive touch not found!");
while (1);
}
Serial.println("Capacitive touch OK!");
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(50, 50);
tft.setTextSize(2);
tft.setTextColor(ILI9341_WHITE);
tft.print("Capacitive Touch OK");
}
void loop() {
if (ctp.touched()) {
TS_Point p = ctp.getPoint();
int x = map(p.x, 0, 240, 0, 320);
int y = map(p.y, 0, 320, 0, 240);
Serial.print("Touch at: ");
Serial.print(x);
Serial.print(", ");
Serial.println(y);
tft.fillCircle(x, y, 3, ILI9341_RED);
}
delay(100);
}