clear adafruit tft screen.

in adafruit tft touch screen

if buff[10] == 'R' i have to clear the screen.
i mean clear previous display things in screen.
i searched for tft.clear function i couldnt find
how to do this ?

if  (buff[10] == 'R')
  { 
   
    tft.fillScreen(GREEN);
    tft.setCursor(180, 150);
    tft.print("11 press R");
    tft.setCursor(100, 220);
    tft.drawRect(tft.width() -80 , tft.height() -40, 90 , 30, WHITE); 
    tft.print("NOWW");
    tft.setCursor(60, 140);
    tft.print("NEXT WHAT");

  }

Why not just fill the screen with your background color, it will write over anything that's on the screen. If you have a fillScr() function, then use it, if not then make one with a simple for loop.

dear its filling screen
but previous sessions still displayed in interval which i used to get the keypad presses. :relaxed:

#define LCD_CS A3 
#define LCD_CD A2   
#define LCD_WR A1   
#define LCD_RD A0   

#define LCD_RESET A4

#define   BLACK           0x0000
#define   BLUE            0x001F
#define   RED             0xF800
#define   GREEN           0x07E0
#define   CYAN            0x07FF
#define   MAGENTA         0xF81F
#define   YELLOW          0xFFE0
#define   WHITE           0xFFFF

#include "TFTLCD.h"
#include <Keypad.h>

const byte ROWS = 5;
const byte COLS = 4;
char buff[11];
long lastUpdate = 0;
int x,i;

TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

char keys[ROWS][COLS] =
{
  {'1','6','A','D'},
  {'2','7','B','E'},
  {'3','8','C','F'},
  {'4','9','X','Y'},
  {'5','0','Z','R'},
 
};

byte rowPins[ROWS] = {40,39,38,37,36}; //connect to row pinouts
byte colPins[COLS] = {32,33,34,35}; //connect to column pinouts

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(void)
{
  Serial.begin(9600);
  Serial.println("8 Bit LCD test!");
  tft.reset();
  tft.initDisplay();

}

void loop(void)
{
  char key = keypad.getKey();

  if (key != NO_KEY) 
  {
    buff[i] = key;
    i = i+1;

   x=x+8;
 
    
  }
  
   if ( i==10)                // ask user to retry or enter the number inputed
  { 
   Serial.println("10th press");
  tft.setCursor(60, 80);
  tft.setTextColor(GREEN);
  tft.setTextSize(2);
  tft.drawRect(tft.width() -60, tft.height() -80, 40 , 25, RED);
  tft.print(" if correct");
  tft.setCursor(70, 100);
  tft.print(" press enter");
  tft.setCursor(60, 120);
  tft.drawRect(tft.width() -60 , tft.height() -80, 40 , 30, RED);  
  tft.print("wrong ");
  tft.setCursor(60, 140);
  tft.print("press cancel");

}
if (buff[10] =='R')                     // action for retry
{
  tft.drawRect(0, 0, tft.width(), tft.height(), WHITE);
  //tft.drawRect(tft.width() -0, tft.height() -0,240,320, CYAN);
  tft.fillRect(0, 0, tft.width(), tft.height(), WHITE);
  tft.setCursor(120, 200);
  tft.setTextColor(GREEN);
  tft.setTextSize(4);
  tft.print(" try again ");}
  
  if (buff[10] =='Z')                      //  // action for enter the number
{tft.fillScreen(CYAN);
  tft.setCursor(180, 190);
  tft.setTextColor(WHITE);
  tft.setTextSize(4);
  tft.print(" number is entered");}




  if((millis() - lastUpdate) > 700)  // has it been >1 second since the last update?
  {
    testtext(BLACK);  
    lastUpdate = millis();
  }
}




void testtext(uint16_t color)          // 10 press in the beginning
{
  tft.fillScreen(BLACK);
  tft.setCursor(50, 20);
  tft.setTextColor(YELLOW);
  tft.setTextSize(2);
  tft.println("HI TEXTS BELOW");
  
 
  tft.setCursor(x, 50);
  tft.setTextSize(2);
  tft.print(buff);

}

Question, what resets i back to zero?

1 Like