Tft LCD..buttons

Sorry folks if this question already asked(I have searched).
I have a TFT LCD Touchscreen which I have programmed to have 3 screens. Access to each screen is controlled by a button. I am using Adafruit GFX library to create the buttons. All the buttons work just fine.

My question is how do I DESTROY a button once created?...This is probably a question covered in other aspects of programming other than purely display programming... But not sure. Any help will be much appreciated.

hi !

i have same problem too !
when i going to next screen that button from the previous screen is still drawed and not removed ?

are you solve it ?

A Button is only a class object. You can destroy it when you have finished with it.

However, most embedded programs would set up all the Buttons once e.g. in setup().
Then draw the correct Buttons when you change screen.

Most people redraw the whole screen when they change screen.

If you have a problem, post a simple sketch that illustrates the problem.


Hi David !

i check your example code with arrays for buttons: is it necessary to make a separate array for each screen ?

yes, i redraw whole screen !!! because without redrawing my buttons not working(updating), and i cant solve this issue !

my program is multi-screen: i want that user can stay in every screen and select a button and go to other screen or select Home and back to home screen - in some screen showing the result of measurement and in one screen select a value for processing the measuring (this is the total of my program !!!)

i start with this code, but not working very well in showing/updating buttons:

its too long i upload the file !

ui-example-test.ino (12.4 KB)

You appear to have 12 different buttons. These will take up some SRAM.

Adafruit_GFX_Button on_btn, off_btn, on_btn1, off_btn1, on_btn2,
                    off_btn2, on_btn3, off_btn3,
                    on_btn10, on_btn11, on_btn12, on_btn13;
// Array of button addresses to behave like a list
Adafruit_GFX_Button *buttons[] = { &on_btn, &off_btn, &on_btn1, &off_btn1, &on_btn2, &off_btn2,
                                   &on_btn3, &off_btn3, &on_btn10, &on_btn11,
                                   &on_btn12, &on_btn13, NULL

I doubt if you want to draw all 12 buttons on one screen.
The buttons array is just pointers. Not much memory.

I would put the correct set of buttons into a pointer array for each screen.

I think that I have posted examples on the Forum for this. i.e. diff set of button pointers for several screens.

I only put “simple” examples in the Library distribution.

You have to be a little careful with Uno memory. 50 buttons with lots of screen arrays might get expensive.


Edit. Attached an example sketch. (2.35 KB)

yes, is it possible with low memory?

i cant find your topic ?! can you send me a link

okay! after reading your code: i don't use this function draw_button_list(); in my code !

let me edit my code . . .