#include <TFT_eSPI.h> // Hardware-specific library
#include <user_setup.h> // Include the user setup file
#include <user_setup_select.h> // Create an instance of the TFT_eSPI class
#ifdef LED_BUILTIN
#define MY_LED LED_BUILTIN // LED_BUILTIN -> On Board Led GPIO pin 2 (D2)
#else
#define MY_LED 2 // On Board Led GPIO pin 2 (D2)
#endif
#define LED_ON HIGH
#define LED_OFF LOW
#define PRJ_NAME "TFT TEST Project" // Project Name
#define DASHED_LINES "\r-------------------------------------------------------\n\r"
#define TFT_GREY 0x5AEB
#define MyBTN 12
// ==================================================
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
// uint32_t targetTime = 0; // for next 1 second timeout
// static uint8_t conv2d(const char* p); // Forward declaration needed for IDE 1.6.x
// uint8_t hh = conv2d(__TIME__), mm = conv2d(__TIME__ + 3), ss = conv2d(__TIME__ + 6); // Get H, M, S from compile time
// byte omm = 99, oss = 99;
// byte xcolon = 0, xsecs = 0;
// unsigned int colour = 0;
// ---------------------------------------------
struct Button {
const uint8_t PIN;
uint32_t numberKeyPresses;
bool pressed;
};
Button button1 = {MyBTN, 0, false};
void ARDUINO_ISR_ATTR isr1() {
// button1.numberKeyPresses += 1;
// button1.pressed = true;
static uint32_t lastMillis;
if ((millis() - lastMillis) > 250) { // Software debouncing buton
button1.numberKeyPresses += 1;
button1.pressed = true;
}
lastMillis = millis();
}
void setup() {
Serial.begin(115200);
delay(10); //
printf("\r\n--------------- Booting ESP ---------------------------\r\n");
printf("Arduino IDE : %d.%d.%d\r\n", ARDUINO / 10000, ARDUINO % 10000 / 100, ARDUINO % 100 / 10 ? ARDUINO % 100 : ARDUINO % 10);
printf("On Board : %s \r\n", ARDUINO_BOARD);
printf("Starting project : %s \r\n", PRJ_NAME);
printf("Author : Kernel Panic \r\n");
printf("Project Date : %s\r\n", (__DATE__ " - " __TIME__));
printf("\t--- SPI -> ESP pin ---\n");
printf("ESP pin MOSI : %d \r\n", (MOSI));
printf("ESP pin MISO : %d \r\n", (MISO));
printf("ESP pin SCK : %d \r\n", (SCK));
printf("ESP pin CS : %d \r\n", (SS));
printf(DASHED_LINES);
pinMode(MY_LED, OUTPUT);
digitalWrite(MY_LED, LED_ON);
tft.init();
tft.setRotation(1); // Or 0, 2, 3 depending on your display
tft.fillScreen(TFT_BLACK); // Clear screen
pinMode(button1.PIN, INPUT_PULLUP);
attachInterrupt(button1.PIN, isr1, FALLING);
// attachInterrupt(digitalPinToInterrupt(button2.PIN), isr, FALLING); // copilot
}
void loop() {
tft.setCursor(10, 10);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(2);
tft.println("Hello Wokwi!");
tft.drawPixel(50, 50, TFT_RED);
delay(1000);
if (button1.pressed) {
button1.pressed = false;
Serial.printf("Button Press times: %lu \n", button1.numberKeyPresses);
}
}Loading
ili9341-cap-touch
ili9341-cap-touch