Hello everyone, I have a small piece of code that works like this: The program starts with a "Hello" message on an ILI9341, 15 seconds later, the "Hello" message is cleared and a menu with 2 buttons appears, Button 1 sets both Button 1 and Button 2 on a green color, while Button 2 sets both buttons back into their standard color (blue). Then an error appears, here is all of it:
In function 'void loop()':
error: 'class TFT_eSPI' has no member named 'getTouch'
if (tft.getTouch(&touchX, &touchY)) {
^
error: 'class TFT_eSPI' has no member named 'getTouch'
if (tft.getTouch(&touchX, &touchY)) {
^
exit status 1
Compilation error: 'class TFT_eSPI' has no member named 'getTouch'
I have Arduino IDE 2.1.0 and I just updated the libraries, I saw a solution that is downgrading the TFT_eSPI from the lastest version to version 2.3.4, I did it, even restarted Arduino, and still nothing. Here's my code:
#include <Arduino.h>
#include <TFT_eSPI.h>
// Initialize TFT display
TFT_eSPI tft;
const unsigned long timerInterval = 15000;
hw_timer_t *timer = NULL;
volatile bool alarmActivated = false;
int buttonX1 = 30; // X-coordinate of the button's top-left corner
int buttonY1 = 30; // Y-coordinate of the button's top-left corner
int buttonX2 = 30; // X-coordinate of the button's top-left corner
int buttonY2 = 70; // Y-coordinate of the button's top-left corner
int tiempo_temp; // Variable to store the selected time
int buttonWidth = 300; // Width of the button
int buttonHeight = 30; // Height of the button
int control1 = 0;
int done = 0;
void drawButton() {
tft.fillRect(10, 30, 300, 30, TFT_BLUE);
tft.fillRect(10, 70, 300, 30, TFT_BLUE);
//-----------------------------------
tft.setTextColor(TFT_WHITE);
tft.setTextSize(2);
tft.drawString("Button 1", 120, 40);
tft.drawString("Button 2", 120, 80);
}
void greenButton() {
tft.fillRect(10, 30, 300, 30, TFT_GREEN);
tft.fillRect(10, 70, 300, 30, TFT_GREEN);
//-----------------------------------
tft.setTextColor(TFT_WHITE);
tft.setTextSize(2);
tft.drawString("Button 1", 120, 40);
tft.drawString("Button 2", 120, 80);
}
void btn1() {
tft.setTextColor(TFT_WHITE);
tft.setTextSize(2);
tft.drawString("Hello", 160, 40);
tft.fillRect(240, 200, 70, 30, TFT_WHITE);
tft.setTextColor(TFT_BLACK);
tft.setTextSize(2);
tft.drawString("Menu", 245, 210);
delay(1000);
}
void btn2() {
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(2);
tft.drawString("Bye", 160, 40);
tft.fillRect(240, 200, 70, 30, TFT_WHITE);
tft.setTextColor(TFT_BLACK);
tft.setTextSize(2);
tft.drawString("Menu", 245, 210);
delay(1000);
}
void IRAM_ATTR callback() {
alarmActivated = true;
}
void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
while (!Serial);
timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &callback, true);
timerAlarmWrite(timer, timerInterval * 1000, true);
Serial.println("Timer started");
}
void loop() {
// Check touch input
uint16_t touchX, touchY;
if (control1 == 1) {
if (done == 0) {tft.fillScreen(TFT_BLACK); drawButton(); done = 1;}
if (tft.getTouch(&touchX, &touchY)) {
// ======================= BUTTON 1 TOUCH ============================
if (touchX >= buttonX1 && touchX <= buttonX1 + buttonWidth && touchY >= buttonY1 && touchY <= buttonY1 + buttonHeight) {
// Button 1 is pressed
greenButton();
}
// ====================== BUTTON 2 TOUCH =============================
if (touchX >= buttonX2 && touchX <= buttonX2 + buttonWidth && touchY >= buttonY2 && touchY <= buttonY2 + buttonHeight) {
// Button 2 is pressed
drawButton();
}
}
}
timerAlarmEnable(timer);
if (control1 == 0) {
if (!alarmActivated) {
btn1();
delay(100);
} else {
control1 = 1;
drawButton();
delay(100);
}
if (tft.getTouch(&touchX, &touchY)) {
if (touchX >= 240 && touchX <= 240 + 70 && touchY >= 200 && touchY <= 200 + 30) {
control1 = 1;
drawButton();
}
}
}
}