// This sketch is to test the touch controller, nothing is displayed
// on the TFT. The TFT_eSPI library must be configured to suit your
// pins used. Make sure both the touch chip select and the TFT chip
// select are correctly defined to avoid SPI bus contention.
// Make sure you have defined a pin for the touch controller chip
// select line in the user setup file or you will see "no member"
// compile errors for the touch functions!
// It is a support and diagnostic sketch for the TFT_eSPI library:
// https://github.com/Bodmer/TFT_eSPI
// The "raw" (unprocessed) touch sensor outputs are sent to the
// serial port. Touching the screen should show changes to the x, y
// and z values. x and y are raw ADC readings, not pixel coordinates.
#include <SPI.h>
#include <TFT_eSPI.h>
TFT_eSPI tft = TFT_eSPI();
//====================================================================
void setup(void) {
Serial.begin(115200);
Serial.println("\n\nStarting...");
tft.init();
tft.setRotation(1);
// Use this calibration code in setup():
tft.fillScreen(tft.color24to16(0xFFFFFF));
tft.fillCircle(100, 100, 60, tft.color24to16(0xC3C3C3));
tft.fillRect(0, 200, 240, 120, tft.color24to16(0x1ABC9C));
tft.fillRect(240, 200, 240, 120, tft.color24to16(0xE74C3C));
tft.setTextSize(6);
tft.setTextColor(tft.color24to16(0x3B3B3B));
tft.setTextDatum(ML_DATUM);
tft.drawString("GPIO14", 200, 100);
tft.setTextSize(4);
tft.setTextColor(tft.color24to16(0xFFFFFF));
tft.setTextDatum(MC_DATUM);
tft.drawString("ON", 120, 260);
tft.drawString("OFF", 360, 260);
}
//====================================================================
void loop() {
uint16_t x, y;
// if (tft.getTouch(&x, &y)) {
// Serial.printf("Touched at (%d, %d)\n", x, y);
// if ((x > 0 && x < 240) && (y > 200 && y < 320)) {
// digitalWrite(14, HIGH);
// tft.fillCircle(100, 100, 60, tft.color24to16(0x27AE60));
// } else if ((x > 240 && x < 480) && (y > 200 && y < 320)) {
// digitalWrite(14, LOW);
// tft.fillCircle(100, 100, 60, tft.color24to16(0xC3C3C3));
// }
// }
// delay(10);
}
//====================================================================