#include <Wire.h>
// Pin configuration
#define SDA_PIN 21
#define SCL_PIN 22
#define RST_PIN 2
// FT6206 constants
#define FT6206_ADDR 0x38
#define FT6206_TOUCHES 0x02
#define FT6206_TOUCH1_XH 0x03
void setup() {
Serial.begin(115200);
// Initialize I2C
Wire.begin(SDA_PIN, SCL_PIN);
Wire.setClock(400000);
// Reset touch controller
pinMode(RST_PIN, OUTPUT);
digitalWrite(RST_PIN, LOW);
delay(10);
digitalWrite(RST_PIN, HIGH);
delay(300);
Serial.println("FT6206 Touch Ready");
}
void loop() {
uint16_t x, y;
if (getTouchCoordinates(&x, &y)) {
Serial.print("Touch: X=");
Serial.print(x);
Serial.print(", Y=");
Serial.println(y);
}
delay(100);
}
// Get touch coordinates
bool getTouchCoordinates(uint16_t *x, uint16_t *y) {
// Check if touched
Wire.beginTransmission(FT6206_ADDR);
Wire.write(FT6206_TOUCHES);
Wire.endTransmission(false);
Wire.requestFrom(FT6206_ADDR, 1);
if (Wire.available() && (Wire.read() & 0x0F) == 0) {
return false; // No touch
}
// Read coordinates
Wire.beginTransmission(FT6206_ADDR);
Wire.write(FT6206_TOUCH1_XH);
Wire.endTransmission(false);
Wire.requestFrom(FT6206_ADDR, 4);
if (Wire.available() >= 4) {
uint8_t xh = Wire.read();
uint8_t xl = Wire.read();
uint8_t yh = Wire.read();
uint8_t yl = Wire.read();
*x = ((xh & 0x0F) << 8) | xl;
*y = ((yh & 0x0F) << 8) | yl;
return true;
}
return false;
}