Como inhabilitar los botones en pantalla tft

poseo una pantalla tft en arduino mega 2560 la en la cual los botones me siguen ejecutando debajo de una grafica, los botones hacen lo que quiero en principio pero no hay un refresco de la pantalla como tal, si no que los botones se siguen ejecutando aun cuando no se ven gráficamente

adjunto codigo //

//Libraries
#include <SD.h>//SD - Arduino Reference
#include <Adafruit_GFX.h>//GitHub - adafruit/Adafruit-GFX-Library: Adafruit GFX graphics core Arduino library, this is the 'core' class that all our other graphics libraries derive from
#include <MCUFRIEND_kbv.h>//GitHub - prenticedavid/MCUFRIEND_kbv: MCUFRIEND_kbv Library for Uno 2.4, 2.8, 3.5, 3.6, 3.95 inch mcufriend Shields
#include <TouchScreen.h> //GitHub - adafruit/Adafruit_TouchScreen: Arduino library for 4-wire resistive touchscreens
//Constants
#define SD_CS 10
#define BLACK 0
#define GREY 21845
#define BLUE 31
#define RED 63488
#define GREEN 2016
#define DARKGREEN 1472
#define CYAN 2047
#define MAGENTA 63519
#define YELLOW 65504
#define GOLD 56768
#define WHITE 65535
//Touch screen configuration
#define MINPRESSURE 200
#define MAXPRESSURE 1000
// ALL Touch panels and wiring is DIFFERENT
// copy-paste results from TouchScreen_Calibr_native.ino
//3.5 Parameters
const int XP = 9, XM = A3, YP = A2, YM = 8; //320x480 ID=0x9486
const int TS_LEFT = 136, TS_RT = 917, TS_TOP = 65, TS_BOT = 962;
//2.8 Parameters
//const int XP = 8, XM = A2, YP = A3, YM = 9; //240x320 ID=0x9341
//const int TS_LEFT = 907, TS_RT = 120, TS_TOP = 74, TS_BOT = 913;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
TSPoint p;
bool down;
int pixel_x, pixel_y; //Touch_getXY() updates global vars
//Variables
int currentPage = 0;
//Objects
MCUFRIEND_kbv tft;
// Button calibration
Adafruit_GFX_Button page1_btn, page2_btn, page3_btn;
int margin = 5;
int btnWidth = 100;
int btnHeight = 40;
int btnY = 200;

void setup() {
//Init Serial USB
Serial.begin(9600);
Serial.println(F("Initialize System"));
//Init tft screen
uint16_t ID = tft.readID();
if (ID == 0xD3D3) ID = 0x9486; //for 3.5" TFT LCD Shield , 0x9341 for 2.8" TFT LCD Shield
tft.begin(ID);
tft.setRotation(1);//0-PORTRAIT 1-PAYSAGE 2-REVERSE PORTRAIT 3-REVERSE PAYSAGE
//Uncomment if you are using SD
/if (!SD.begin(SD_CS)) {
Serial.println(F("initialization failed!"));
return;
}
/
drawStart();

}
void loop() {
down = Touch_getXY();
if (currentPage == '0') {
Serial.println(F("Page 0"));
drawStart();
}

page2_btn.press(down && page2_btn.contains(pixel_x, pixel_y));
//if (page1_btn.justReleased()) page2_btn.drawButton();
if (page2_btn.justPressed()) {
drawInicio();
}

page3_btn.press(down && page3_btn.contains(pixel_x, pixel_y));
//if (page3_btn.justReleased()) page2_btn.drawButton();
if (page3_btn.justPressed()) {
drawGrafica();
}

page1_btn.press(down && page1_btn.contains(pixel_x, pixel_y));
//if (page1_btn.justReleased()) page2_btn.drawButton();
if (page1_btn.justPressed()) {
drawIngresarParametros();
}

}
void drawStart() {
//==============INTRO
tft.setRotation(1);
tft.fillScreen(BLACK);
tft.setCursor(100, 150);
tft.setTextSize(7 / 2);
tft.setTextColor(WHITE, BLACK);
tft.print(">> INICIANDO <<");
delay(2000);
tft.fillScreen(BLACK);
delay(1000);
tft.setCursor(130, 150);
tft.setTextSize(7 / 2);
tft.setTextColor(WHITE, BLACK);
tft.print("BIENVENIDO!");
for (int i = 15; i < 304; i += 5)
{
tft.drawLine(1, i, (i * 1.6) - 10, 304, RED);
}
for (int i = 304; i > 15; i -= 5)
{
tft.drawLine(478, i, (i * 1.6) - 11, 15, RED);
}
delay(2000);
tft.fillScreen(BLACK);
page2_btn.initButton(&tft, 240, 160, 200, 50, WHITE, BLACK, WHITE, "INICIAR", 4);
page2_btn.drawButton(false);

}

void drawInicio() {

//=================Title
tft.setRotation(1);
tft.fillScreen(BLACK);
tft.setCursor(105, 10);
tft.setTextSize(2);
tft.setTextColor(WHITE, BLACK);
tft.print(">> TOSTADORA DE CAFE <<"); // Prints the string on the screen
tft.drawLine(80, 32, 400, 32, RED); // Draws the red line
//text
tft.setCursor(200, 40);
tft.setTextSize(2);
tft.setTextColor(WHITE, BLACK);
tft.print("Opciones"); // Prints the string on the screen
//options
///Ingresar Parametros
//btnP();
page1_btn.initButton(&tft, 100, 140, 120, 100, RED, WHITE, BLACK, "P", 4);
page1_btn.drawButton(false);
tft.setCursor(50, 200);
tft.setTextSize(2);
tft.setTextColor(WHITE, BLACK);
tft.print("Ingresar");
tft.setCursor(40, 220);
tft.setTextSize(2);
tft.setTextColor(WHITE, BLACK);
tft.print("Parametros");
///Grafica Temperatura vs Tiempo
//btnG();
page3_btn.initButton(&tft, 240, 140, 120, 100, RED, CYAN, BLACK, "G", 4);
page3_btn.drawButton(false);
/tft.setCursor(200, 200);
tft.setTextSize(2);
tft.setTextColor(WHITE, BLACK);
tft.print("Grafica");
tft.setCursor(175, 220);
tft.setTextSize(2);
tft.setTextColor(WHITE, BLACK);
tft.print("C vs Tiempo");
///Historial en SD
page1_btn.initButton(&tft, 380, 140, 120, 100, RED, MAGENTA, BLACK, " ", 1);
page1_btn.drawButton(false);
tft.setCursor(320, 200);
tft.setTextSize(2);
tft.setTextColor(WHITE, BLACK);
tft.print("Historial SD");
/

tft.setCursor(10, 310);
tft.setTextSize(1 / 2);
tft.setTextColor(WHITE, BLACK);
tft.print("Developed by H&S Asc.");

}
/*
void btnP() {
page1_btn.initButton(&tft, 100, 140, 120, 100, RED, WHITE, BLACK, "P", 4);
page1_btn.drawButton(false);
}

void btnG() {
page3_btn.initButton(&tft, 240, 140, 120, 100, RED, CYAN, BLACK, "G", 4);
page3_btn.drawButton(false);
}
*/
void drawIngresarParametros() {

tft.setRotation(1);
tft.fillScreen(BLACK);
tft.setCursor(10, 15);
tft.setTextSize(1);
tft.setTextColor(WHITE, BLACK);
tft.print("Parametros");
tft.drawLine(0, 30, 200, 30, RED);
tft.setCursor(40, 80);
tft.setTextSize(2);
tft.setTextColor(WHITE, BLACK);
tft.print("Temperatura");
tft.fillRect(37, 97, 166, 56, RED);
tft.fillRect(40, 100, 160, 50, WHITE);
//======
tft.setCursor(40, 160);
tft.setTextSize(2);
tft.setTextColor(WHITE, BLACK);
tft.print("Peso - gramos");
tft.fillRect(37, 177, 166, 56, RED);
tft.fillRect(40, 180, 160, 50, WHITE);

page2_btn.initButton(&tft, 400, 305, 70, 15, BLACK, BLACK, WHITE, "< Regresar ", 2);
page2_btn.drawButton(false);
tft.setCursor(10, 310);
tft.setTextSize(1 / 2);
tft.setTextColor(WHITE, BLACK);
tft.print("Developed by H&S Asc.");

}

void drawGrafica() {
tft.setRotation(1);
tft.fillScreen(BLACK);
tft.setCursor(10, 15);
tft.setTextSize(1);
tft.setTextColor(WHITE, BLACK);
tft.print("Temperatura vs Tiempo");
tft.drawLine(0, 30, 200, 30, RED);
tft.drawLine(20, 50, 20, 305, WHITE);
tft.drawLine(10, 295, 460, 295, WHITE);

page2_btn.initButton(&tft, 400, 305, 70, 15, BLACK, BLACK, WHITE, "< Regresar ", 2);
page2_btn.drawButton(false);
tft.setCursor(10, 310);
tft.setTextSize(1 / 2);
tft.setTextColor(WHITE, BLACK);
tft.print("Developed by H&S Asc.");

}

bool Touch_getXY(void)
{
p = ts.getPoint();
pinMode(YP, OUTPUT); //restore shared pins
pinMode(XM, OUTPUT);
digitalWrite(YP, HIGH);
digitalWrite(XM, HIGH);
bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
if (pressed) {
if (tft.width() <= tft.height()) { //Portrait
pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
} else {
pixel_x = map(p.y, TS_TOP, TS_BOT, 0, tft.width());
pixel_y = map(p.x, TS_RT, TS_LEFT, 0, tft.height());
}
}
return pressed;
}

Su publicacion se MUEVE a su ubicacion actual ya que es mas adecuada.

Moderador:
Por favor, lee las Normas del foro y edita tu código/error usando etiquetas de código.
Ve a edición, luego selecciona todo el código que has publicado, lo cortas y click en </>


This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.