Hola TFT LCDCyg, muchas gracias por tu atención. El código que utilizo es este:
#include <Adafruit_GFX.h>
#if defined(_GFXFONT_H_) //are we using the new library?
#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSerifBold18pt7b.h>
#define ADJ_BASELINE 11 //new fonts setCursor to bottom of letter
#else
#define ADJ_BASELINE 0 //legacy setCursor to top of letter
#endif
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#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 0x7BEF
#define Pin13LED 13
#include <stdio.h>
int byteReceived;
int valorAnterior = 0;
int consultaRem;
int byteSend;
int buzzPresion;
int disparo = 0;
int ca;
int valorAnteriorca = 0;
#define RS485Transmit HIGH
#define RS485Receive LOW
#define SSerialTxControl 22 //RS485 Direction control
uint16_t ID;
uint8_t hh, mm, ss; //containers for current time
uint8_t conv2d(const char* p)
{
uint8_t v = 0;
if ('0' <= *p && *p <= '9') v = *p - '0';
return 10 * v + *++p - '0';
}
void setup(void)
{
pinMode(48, OUTPUT);
Serial.begin(9600);
Serial1.begin(9600);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver
tft.reset();
ID = tft.readID();
Serial.print("TFT ID = 0x");
Serial.println(ID, HEX);
// if (ID == 0x00D3) ID = 0x9481; // write-only shield
if (ID == 0x00D3) ID = 0x9486; // write-only shield
tft.begin(ID);
tft.setRotation(1);
tft.fillScreen(WHITE);
//#if defined(_GFXFONT_H_)
// tft.setFont(&FreeSans9pt7b);
tft.setFont(&FreeSerifBold18pt7b);
/*#endif
hh = conv2d(__TIME__);
mm = conv2d(__TIME__ + 3);
ss = conv2d(__TIME__ + 16);*/
}
void loop(void)
{
int16_t x, y, dx, dy, idx;
uint16_t w, h, len, mask, pasovert = 48;
uint16_t colors[8] = { BLACK, WHITE, YELLOW, CYAN, GREEN, MAGENTA, RED, BLUE };
uint16_t height, width;
width = tft.width();
height = tft.height();
//Serial.flush();
//------------------------------------------------------------------
//------------------------------------------------------------------
digitalWrite(SSerialTxControl, RS485Receive); // Disable RS485 Transmit
if (Serial1.available()) //Look for data from other Arduino
{
byteReceived = Serial1.read(); // Read received byte
if (byteReceived == 65) {
tft.setCursor(1, 2 + pasovert * 2);
//tft.fillScreen(WHITE);
tft.setTextColor(GREEN, WHITE);
tft.setTextSize(1);
tft.print(" Area 1 = ARMADO ");
delay(500);
}
if (byteReceived == 67) {
tft.setCursor(1, 2 + pasovert * 2);
tft.setTextColor(RED, WHITE);
tft.setTextSize(1);
tft.print("Area 1 = FALLA PRESION");
delay(500);
}
if (byteReceived == 69) {
tft.setCursor(1, 2 + pasovert * 2);
tft.setTextColor(RED, WHITE);
tft.setTextSize(1);
tft.print(" AREA 1 = FALLA ZONA ");
delay(500);
}
Con esto le digo en quie linea tiene que escribir
tft.setCursor(1, 2 + pasovert * 2);
y si para la misma linea cambia la información, sobreescribe.
Un colega me pasó este código de un reloj que borra dibujando un rectángulo. Tal vez lo pueda adaptar a mi código, escribiendo un rectángulo blanco, ya que el fondo es blanco, y así producir un borrado.
// Si fuese SPI seria mucho mas rapida, en este caso l ainterfase es paralelo 8 bits
#include <Adafruit_GFX.h>
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#if defined(_GFXFONT_H_) //are we using the new library?
#include <Fonts/FreeSerifBold12pt7b.h>
#define ADJ_BASELINE 14 //new fonts setCursor to bottom of letter
#else
#define ADJ_BASELINE 0 //legacy setCursor to top of letter
#endif
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
uint8_t YP = A1; // must be an analog pin, use "An" notation!
uint8_t XM = A2; // must be an analog pin, use "An" notation!
uint8_t YM = 7; // can be a digital pin
uint8_t XP = 6; // can be a digital pin
#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 0x7BEF
#include <stdio.h>
uint16_t ID;
uint8_t hh, mm, ss; //containers for current time
uint16_t ancho_pantalla, alto_pantalla;
int16_t posx = 20, posy = 80, x,y,x1,y1, tamanotexto = 1;
uint16_t w,h;
uint8_t conv2d(const char* p)
{
uint8_t v = 0;
if ('0' <= *p && *p <= '9') v = *p - '0';
return 10 * v + *++p - '0';
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
tft.reset();
ID = tft.readID();
Serial.print("Pantalla TFT ID = 0x");
Serial.println(ID, HEX);
// if (ID == 0x00D3) ID = 0x9481; // write-only shield
if (ID == 0x00D3) ID = 0x9488; // write-only shield
tft.begin(ID);
tft.setRotation(1);
tft.setTextSize(tamanotexto);
tft.fillScreen(BLACK);
#if defined(_GFXFONT_H_)
tft.setFont(&FreeSerifBold12pt7b);
#endif
ancho_pantalla = tft.width();
alto_pantalla = tft.height();
Serial.print("El ancho horizontal en pixels es ");
Serial.println(ancho_pantalla);
Serial.print("La altura vertical en pixels es ");
Serial.println(alto_pantalla);
// Toma la hora de las variables del compilador - Se borra al desconectar el arduino
hh = conv2d(__TIME__);
mm = conv2d(__TIME__ + 3);
ss = conv2d(__TIME__ + 16);
}
void loop() {
// put your main code here, to run repeatedly:
while (1) {
for (tamanotexto = 1; tamanotexto < 5; tamanotexto++){ tft.setTextSize(tamanotexto);
if (++ss > 59) {
ss = 0;
mm++;
if (mm > 59) {
mm = 0;
hh++;
if (hh > 23) hh = 0;
}
}
char buf[20];
sprintf(buf, "%02d:%02d:%02d", hh, mm, ss); // almacena la hora en buf con formato de dos digitos
tft.setCursor(posx,posy);
tft.setTextColor(RED);
tft.print(buf);
delay(1000);
tft.getTextBounds(buf, x, y, &x1, &y1, &w, &h);
tft.drawRect(posx, posy-(ADJ_BASELINE+2)*tamanotexto, w+tamanotexto*2, h+tamanotexto, YELLOW); // Solo para ver el area a borrar, se puede eliminar
tft.fillRect(posx, posy-(ADJ_BASELINE+2)*tamanotexto, w+tamanotexto*2, h+tamanotexto, BLACK); // Borra el area
}
} // Fin de while
} // Fin de loop
Gracias de antemano