#include <TFT_eSPI.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_TouchScreen.h> // Include the Adafruit TouchScreen library
#define XP D22
#define YP D19
#define XM D23
#define YM D18
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
Adafruit_TouchScreen touch = Adafruit_TouchScreen(XP, YP, XM, YM, 300); // Specify the pins for the touch screen
void setup() {
Serial.begin(115200);
tft.init();
tft.setRotation(1); // Landscape orientation
// Initialize touch
if (!touch.begin()) {
Serial.println("Touch init fail");
}
// Clear the screen
tft.fillScreen(TFT_BLACK);
}
void loop() {
// Get touch coordinates
TS_Point p = touch.getPoint(); // Retrieve touch point
// Map touch coordinates to screen dimensions
int16_t x = map(p.x, 0, 240, 0, tft.width());
int16_t y = map(p.y, 0, 320, 0, tft.height());
// Print coordinates to serial monitor
Serial.print("X = ");
Serial.print(x);
Serial.print(", Y = ");
Serial.println(y);
// Draw a point at the touched position
tft.drawPixel(x, y, TFT_WHITE);
// Add your smartwatch functionality here
// For example, displaying time, date, notifications, etc.
}
Loading
ili9341-cap-touch
ili9341-cap-touch