@ScruffR, yes, below is the full test code:
#include "Adafruit_mfGFX.h"
#include "Adafruit_ILI9341.h"
#include "XPT2046.h"
Adafruit_ILI9341 tft = Adafruit_ILI9341(A2, A1, A0);
XPT2046 touch(DAC, WKP); // CS, IRQ
static void calibratePoint(uint16_t x, uint16_t y, uint16_t &vi, uint16_t &vj) {
// Draw cross
tft.drawFastHLine(x - 8, y, 16,0xff);
tft.drawFastVLine(x, y - 8, 16,0xff);
while (!touch.isTouching()) {
tft.setTextSize(2);
tft.println("N");
Serial.println("Not Touch");
delay(10);
}
touch.getRaw(vi, vj);
// Erase by overwriting with black
tft.drawFastHLine(x - 8, y, 16, 0);
tft.drawFastVLine(x, y - 8, 16, 0);
}
void calibrate() {
uint16_t x1, y1, x2, y2;
uint16_t vi1, vj1, vi2, vj2;
touch.getCalibrationPoints(x1, y1, x2, y2);
calibratePoint(x1, y1, vi1, vj1);
delay(1000);
calibratePoint(x2, y2, vi2, vj2);
touch.setCalibration(vi1, vj1, vi2, vj2);
tft.setRotation(3);
tft.setTextColor(ILI9341_CYAN);
tft.setTextSize(2);
tft.println("Calibration Params");
tft.println("");
tft.setTextSize(3);
tft.println(vi1);
tft.println(vj1);
tft.println(vi2);
tft.println(vj2);
}
void setup() {
Serial.begin(9600);
delay(1000);
// SPI.setFrequency(ESP_SPI_FREQ);
tft.begin();
touch.begin(tft.width(), tft.height()); // Must be done before setting rotation
tft.fillScreen(ILI9341_BLACK);
calibrate(); // No rotation!!
}
void loop() {
// Do nothing
uint16_t x, y;
if (touch.isTouching()) {
touch.getPosition(x, y);
Serial.println("position");
Serial.println(x);
Serial.println(y);
} else {
Serial.println("No");
}
delay(1000);