#include <SPI.h>
#include <TFT_eSPI.h>
// Install the "XPT2046_Touchscreen" library by Paul Stoffregen to use the Touchscreen - https://github.com/PaulStoffregen/XPT2046_Touchscreen
// Note: this library doesn't require further configuration
#include <XPT2046_Touchscreen.h>
// Create a TFT_eSPI instance:
TFT_eSPI tft = TFT_eSPI();
// Touchscreen pins
#define XPT2046_IRQ 36 // T_IRQ
#define XPT2046_MOSI 32 // T_DIN
#define XPT2046_MISO 39 // T_OUT
#define XPT2046_CLK 25 // T_CLK
#define XPT2046_CS 33 // T_CS
// Create a touchscreenSPI and touchscreen instances:
SPIClass touchscreenSPI = SPIClass(VSPI);
XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ);
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#define FONT_SIZE 4
// Touchscreen coordinates: (x, y) and pressure (z)
int x, y, z;
void setup() {
Serial.begin(115200);
// Start the SPI for the touchscreen and init the touchscreen
touchscreenSPI.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
touchscreen.begin(touchscreenSPI);
// Set the Touchscreen rotation in landscape mode
// Note: in some displays, the touchscreen might be upside down, so you might need to set the rotation to 3: touchscreen.setRotation(3);
touchscreen.setRotation(3);
// Start the tft display
tft.init();
// Set the TFT display rotation in landscape mode, 1 will flip display 180 degrees
tft.setRotation(3);
// Clear the screen before writing to it
tft.fillScreen(TFT_WHITE);
tft.setTextColor(TFT_BLACK, TFT_WHITE);
// // Set X and Y coordinates for center of display
// int centerX = SCREEN_WIDTH / 2;
// int centerY = SCREEN_HEIGHT / 2;
// tft.drawCentreString("Hello, world!", centerX, 30, FONT_SIZE);
// tft.drawCentreString("Touch screen to test", centerX, centerY, FONT_SIZE);
}
void loop() {
tft.fillRectVGradient(200, 70, 50, 100, TFT_RED,TFT_BLUE );
tft.fillRect(0, 0, 320, 30, TFT_RED);
tft.fillRect(10, 200, 93, 30, TFT_RED);
tft.fillRect(113, 200, 93, 30, TFT_RED);
tft.fillRect(216, 200, 93, 30, TFT_RED);
// tft.setTextColor(TFT_RED, TFT_WHITE);
// tft.drawString("SetUp", 200, 20, 4);
delay(100);
}
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4
Loading
ili9341-cap-touch
ili9341-cap-touch