LCD/TFT and flickering...

Dear all :). I have finally gotten my 2,4" TFT touchscreen to do what I want it to :wink: (rotation etc...) and I am trying to build a menu system on it.
I have created a function for the startscreen and I load this in setup(). I am also using a variable called scrren, to indicate which screen I am showing. (will upload code once it is cleaned up a bit).

So, imagine this. In the startscreen function, I draw the buttons and I set screen = 0.

In loop() I have a simple if(screen ==0){ //check if buttons have been touched and set screen = 1 (or 2 depending on which button i touched)}
I have another if(screen == 1){ //here I draw some other buttons and will eventually check if they are touched, to do the necessary actions} which brings me to my question... When screen 1 is showing, all the buttons and text flicker (surely due to the loop refresh rate...).

Does anyone have an idea how I can let the code in loop draw the buttons etc. just once and not over and over again? Would it be easier if I moved the drawing of the buttons and text in screen 1 to a function? More like the startscreen?

Sorry if I am not making any sense, it does make sense in my head ;). Hope someone will understand it...

You'll have to post all your code to get a chance of a good answer. However, in principle, you should redraw the screen only when there is a change or an event has been detected e.g. a button being pressed, a temperature rising one degree etc. etc. Don't simply redraw it every loop iteration.

Incidentally, what screen have you purchased (post a link to it). I've just spent some time developing a navigation bar class for a 2.8 inch SPI touch screen which handles the generation of buttons on screen and the detection of button presses with call back routines.

Your program has different "states", e.g. pages on display.
And it needs to do actions, e.g. update the display.

So you best take a piece of paper and draw a state-transition-diagram.

On the transition you note the actions needed, e.g. the updates to the screen.

The action names could then directly be the names of the functions that do the action.

Good luck!

Excellent advice people :D. I now have a few ideas and I have sorted out the flickering of screen two. Will work on the other screens/menus with your guidance in mind. Hopefully I will accomplish what I have set as my goal. Will post my code as soon as it is complete/working.

The TFT/LCD I am using is this one (or similar to this one): 2.4" TFT LCD Shield Touch Panel Module TF Micro SD | eBay

I am using the following libraries to make it go:
Adafruit_GFX
SWTFT
Touchscreen