TFT 3.5 switching menu

Hello everyone!
I have a trouble with my project. I want switching two menu on tft. And the wrong here i can only switch one menu and then i can’t switch anymore.
Anyone can help me and tell me I wrong somewhere.
here is my code:
/////
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000

// ALL Touch panels and wiring is DIFFERENT
// copy-paste results from TouchScreen_Calibr_native.ino
const int XP = 6, XM = A2, YP = A1, YM = 7; //ID=0x9341
const int TS_LEFT = 907, TS_RT = 136, TS_TOP = 942, TS_BOT = 139;

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
// khai báo màu
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define GREY 0xBDF7
#define DRAK 0x7BEF
/// Khai bao RỘNG VÀ DÀI
#define BUTTON_X 420
#define BUTTON_Y 220
#define BUTTON_W 68
#define BUTTON_H 60
#define BUTTON_SPACING_X 07
#define BUTTON_SPACING_Y 07

// Khai báo các số
char buttonlabels[12][6]={“DE”,“CLE”,“0”,“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”};
uint16_t buttoncolors[12] = {GREEN,WHITE,GREY,GREY,GREY,GREY,GREY,GREY,GREY,GREY,GREY,GREY};
Adafruit_GFX_Button buttons[12], EN;
// Lập trình TOUCH
int pixel_x, pixel_y; //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
TSPoint p = ts.getPoint();
pinMode(YP, OUTPUT); //restore shared pins
pinMode(XM, OUTPUT);
bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
if (pressed) {
// most apps use Portrait or Landscape. No need for all 4 cases
switch (tft.getRotation()) {
case 0:
pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width());
pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
break;
case 1:
pixel_x = map(p.y, TS_TOP, TS_BOT, 0, tft.width());
pixel_y = map(p.x, TS_RT, TS_LEFT, 0, tft.height());
break;
case 2:
pixel_x = map(p.x, TS_RT, TS_LEFT, 0, tft.width());
pixel_y = map(p.y, TS_BOT, TS_TOP, 0, tft.height());
break;
case 3:
pixel_x = map(p.y, TS_BOT, TS_TOP, 0, tft.width());
pixel_y = map(p.y, TS_LEFT, TS_RT, 0, tft.height());
break;
}
}
return pressed;
}
//
bool hian=true;
TSPoint tp;
int i=0,j=0,z=0;
int menu;
void setup()
{
Serial.begin(9600);
tft.reset();
uint16_t ID = tft.readID();
Serial.print(“TFT ID = 0x”);
Serial.println(ID, HEX);
Serial.println(“Calibrate for your Touch Panel”);
if (ID == 0xD3D3) ID = 0x9486; // write-only shield
tft.begin(ID);
tft.setRotation(1);
tft.fillScreen(BLACK);
menu=0;
}
void hoan(){
tft.fillScreen(GREY);
bool down = Touch_getXY();
if(down){
if(menu==0){
menu=1;
}
}
}
void number(){
// Lập trình các khối (DRAW)
for (i=0;i<2;i++){
for(j=0;j<6;j++)
{
buttons[z].initButton(&tft, BUTTON_X-j*(BUTTON_W+BUTTON_SPACING_X), BUTTON_Y-i*(BUTTON_H+BUTTON_SPACING_Y), BUTTON_W, BUTTON_H, BLACK, buttoncolors[z],BLACK,buttonlabels[z], 3);
buttons[z].drawButton();
z++;
}
}
EN.initButton(&tft,220,285,435,58,BLACK,CYAN,BLACK,“EN”,3);
EN.drawButton(false);
}
#define text_x 10
#define text_y 10
#define text_w 10
#define text_h 10
#define text_len 4
char textfield[text_len +1]="";
uint8_t textfield_i=0;
////
void draw(){
/// Khai báo phần cảm ứng
bool down = Touch_getXY();
int m;
/// check các button xem có được bấm ko
for (uint8_t b=0 ;b<12; b++){
if(buttons.contains(pixel_x,pixel_y)){
buttons.press(true);
}
else{
buttons.press(false);
}
}
// Check có thả number ra hay không
for (uint8_t b=0; b<12; b++) {
if (buttons.justReleased()) {
// Serial.print("Released: "); Serial.println(b);
buttons.drawButton(false); // draw normal
}

if (buttons.justPressed()) {
buttons.drawButton(true); // draw invert!
// press number
if (b >= 2) {
if (textfield_i < text_len) {
textfield[textfield_i] = buttonlabels

  • ;

textfield_i++;
textfield[textfield_i] = 0; // zero terminate
// fona.playDTMF(buttonlabels

  • );

}
}

// clr button! delete number
if (b == 0) {
textfield[textfield_i] = 0;
if (textfield > 0) {
textfield_i–;
textfield[textfield_i] = ’ ';
}
}
// update the current text field
Serial.println(textfield);
tft.setCursor(text_x + 2, text_y+10);
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(5);
tft.print(textfield);

}
}
EN.press(down && EN.contains(pixel_x, pixel_y));
if(EN.justReleased()){
EN.drawButton();
}
if(EN.justPressed()){
EN.drawButton(true);
Serial.println(“Đã bấm”);
menu=0;
}
}

void loop(void){

switch(menu){
case 0: hoan();break;
case 1: number();menu=2;break;
case 2: draw();break;

}
}
////
p.s: Sorry my English not good so much. If anyone not understan i wrote please comment below to i can fix that.

Please follow the advice on posting a programming question given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

@hoan69 - your duplicate post in the Displays section has been deleted

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a timeout from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

and the other duplicate in this section

and yet another one in Displays

STOP POSTING DUPLICATE QUESTIONS OR YOU RUN THe RISK OF A BAN