// Work in progress
// ----------------
//
//
// Cheap Yellow Display
//
// Following tutorial:
// https://www.esp32s.com/blog/esp32-cheap-yellow-display-cyd-complete-getting-started-guide/
//
// Introduced in Wokwi:
// https://wokwi.com/projects/456026462310392833
/* ESP32 CYD Getting Started Test
Displays text and prints touch coordinates to screen and Serial Monitor
Full tutorial: https://RandomNerdTutorials.com/cyd/
*/
#include <SPI.h>
#include <TFT_eSPI.h> // Display library
#include <XPT2046_Touchscreen.h> // Touch library
#include "User_Setup.h"
TFT_eSPI tft = TFT_eSPI();
// Touchscreen pin definitions for CYD
#define XPT2046_IRQ 36
#define XPT2046_MOSI 32
#define XPT2046_MISO 39
#define XPT2046_CLK 25
#define XPT2046_CS 33
SPIClass touchscreenSPI = SPIClass(VSPI);
XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ);
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#define FONT_SIZE 2
int touchX, touchY, touchZ;
void printTouchToSerial(int x, int y, int z) {
Serial.print("X = "); Serial.print(x);
Serial.print(" | Y = "); Serial.print(y);
Serial.print(" | Pressure = "); Serial.println(z);
}
void printTouchToDisplay(int x, int y, int z) {
tft.fillScreen(TFT_WHITE);
tft.setTextColor(TFT_BLACK, TFT_WHITE);
int centerX = SCREEN_WIDTH / 2;
int textY = 80;
tft.drawCentreString("X = " + String(x), centerX, textY, FONT_SIZE);
textY += 20;
tft.drawCentreString("Y = " + String(y), centerX, textY, FONT_SIZE);
textY += 20;
tft.drawCentreString("Pressure = " + String(z), centerX, textY, FONT_SIZE);
}
void setup() {
Serial.begin(115200);
Serial.println("ESP32 CYD Starting...");
// Initialize touchscreen
touchscreenSPI.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
touchscreen.begin(touchscreenSPI);
// Set landscape orientation (try 3 if touches are reversed)
touchscreen.setRotation(1);
// Initialize display
tft.init();
tft.setRotation(1); // Landscape mode
tft.fillScreen(TFT_WHITE);
tft.setTextColor(TFT_BLACK, TFT_WHITE);
int centerX = SCREEN_WIDTH / 2;
int centerY = SCREEN_HEIGHT / 2;
tft.drawCentreString("Hello, CYD!", centerX, 30, FONT_SIZE);
tft.drawCentreString("Touch to test", centerX, centerY, FONT_SIZE);
}
void loop() {
if (touchscreen.tirqTouched() && touchscreen.touched()) {
TS_Point p = touchscreen.getPoint();
// Map raw touch values to screen coordinates
// These values work for most CYD boards; adjust if needed
touchX = map(p.x, 200, 3700, 1, SCREEN_WIDTH);
touchY = map(p.y, 240, 3800, 1, SCREEN_HEIGHT);
touchZ = p.z;
printTouchToSerial(touchX, touchY, touchZ);
printTouchToDisplay(touchX, touchY, touchZ);
delay(100); // Simple debounce
}
}Loading
esp32-2432s028r
esp32-2432s028r