Compile error in Touch screen

I'm trying to learn from existing TFT_eSPI example Button.h
but the sketch won't compile. What am I doing wrong?
I just cant"C"it

Compilation error in TFT_eSPI_Button.h

void loop() {
  // Check if the button is pressed
  if (btn.contains(tft.getTouchX(), tft.getTouchY())) {
    // Button is pressed, do something
    tft.fillScreen(TFT_GREEN);
    delay(500);
    tft.fillScreen(TFT_BLACK);
    btn.drawButton();
  }
} 

Compilation error: 'class TFT_eSPI' has no member named 'getTouchX'; did you mean 'getTouch'?

The error is telling you that this isn't a member of the class. It is suggesting maybe the X is a typo.

Show entire source in code tags. Show entire verbose error log in code tags

Looks like maybe you got the code example from here?

https://doc-tft-espi.readthedocs.io/tft_espi_button/constructor/

But maybe that's out of date, because the source code now only has the getTouch method?

Thanks for your reply. I'm in the early stage of learning what the lines of "C" mean. I have no clue what's "class" or how to make the "working example" work.

Well, classes are actually a part of C++ but you probably need to start with more basic programming and work your way up.

1 Like

Then you've jumped in over your head. Take some time to learn the basics and work your way up to these more complicated topics.

These are the basics. Hello World and simple button. That's where all the "C" tutorials start.

Simple C tutorials don't start out with TFT libraries. Usually younstart out just printing stuff to the screen. Arduino basic examples start out with reading and writing physical IO pins.

1 Like

I understand hardware. I setup my test esp32 with switches and LEDs. I programmed inputs and outputs. I have done that and also programmed LCD with touchscreen on Microchip PIC32 in MMBasic, I learned assembly language on IBM PC and I built website in HTML, but I just don't get C language. This is a good example of how impossible it is to find clear explanation of basically hidden code of a compiler.

None of those things teach you anything about the C++ language.

Point being, if you don't know what classes are in C++ then it will be hard to understand this. Despite how many other things you think you know, none of those things include how classes work in C++. So before you get too far along, it would probably hlp for you to learn about classes in C++.

I can't help but laugh at the level of disingenuousness when you follow

With this rant about how much you know. It doesn't matter what else you know. You don't know the thjng you need here. It is useless to tell me about your HTML skills. They don't apply here.

This is obviously a new topic for you. Treat it as one.

There is a clear explanation. You currently don't have the knowledge or vocabulary to understand it because classes are new to you. That isn't a fault with the explanation. That fault is in your understanding. To someone who knows how classes work this is trivial.

Blink is where all Arduino tutorials start.

You're code snippit looks nothing at all like the example. I would start there.

Yes, I'm fully aware that knowing the English language won't make you understand Spanish. The way I learned some programming was what was the standard at different times of microcontrollers evolution. Basic was acceptable language and had capability of in-line assembly for added execution speed. There was clearly explained documentation (some may remember Spontaneous Assembly or Peter Norton assembly for PC) and computers came with bunch of good books. Even HTML-4 was a great book. I wish, C and C++ examples were that clear. Whatever I read now on C language assumes you understand the language. Daah. If I unerstud, I wouldn't be reading it. I would be writing it.

Not when you start from the very beginning.

It would not be crazy to pick up K&R C (the latest edition) and/or maybe the C++ Primer. It might feel like you're taking a long detour to getting your project working but everything is going to go so much faster if you understand the programming language! :slight_smile:

Can you suggest link or a book?

I did the Hello World, I did Blink LED, I did switch inputs to light up LEDs on output, I solved some timing issues, done basic troubleshooting, but none of that started with clear learning steps. It just jumps from one topic to next.

That's where I learned it. It isn't exciting. It isn't a ton of fun. But it will take you one step at a time through understanding the language.

Thank you. I found it and will read it.

1 Like