Display a variable in TFT Screen without blink

Hi.I am using Arduino TFT LCD screen 1.77" .details of the display is given in the below link.

http://arduino.cc/en/Main/GTFT

I am trying to interface this with Arduino Micro Board.I have used the Example sketch from Arduino IDE to display the Text in the TFT screen.
(Arduino IDE->File->Example->TFT->Arduino->TFTDisplay Text)

This is my code.

#include <TFT.h>  // Arduino LCD library
#include <SPI.h>

// pin definition for the Uno
#define cs   10
#define dc   9
#define rst  8  

// pin definition for the Leonardo
// #define cs   7
// #define dc   0
// #define rst  1 

// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);

// char array to print to the screen
char sensorPrintout[4];

void setup() {
  
  // Put this line at the beginning of every sketch that uses the GLCD:
  TFTscreen.begin();

  // clear the screen with a black background
  TFTscreen.background(0, 0, 0);
  
  // write the static text to the screen
  // set the font color to white
  TFTscreen.stroke(255,255,255);
  // set the font size
  TFTscreen.setTextSize(2);
  // write the text to the top left corner of the screen
  TFTscreen.text("Sensor Value :\n ",0,0);
  // ste the font size very large for the loop
  TFTscreen.setTextSize(5);
}

void loop() {

  // Read the value of the sensor on A0
  String sensorVal = String(analogRead(A0));
 
  // convert the reading to a char array
  sensorVal.toCharArray(sensorPrintout, 4);

  // set the font color
  TFTscreen.stroke(255,255,255);
  // print the sensor value
  TFTscreen.text(sensorPrintout, 0, 20);
  // wait for a moment
  delay(250);
  // erase the text you just wrote
  TFTscreen.stroke(0,0,0);
  TFTscreen.text(sensorPrintout, 0, 20);
}

Above code works fine and continuously display the variable with blink of every 250ms.
If I remove the following part from the above code

TFTscreen.stroke(0,0,0);
TFTscreen.text(sensorPrintout, 0, 20);

It stops blinking.But new value is superimposed with old value.I would like to display a variable without blinking.
How to resolve this problem?

1) caching you can remember the last value written (e.g. in a global variable) and if the new value is the same, you do not write anything to the screen.

void loop() 
{
  int x = analogRead(A0);
  if (x != prevX) 
  {
    // write prevX in white

    // write x in black

  // remember last value
    prevX = x;
  }
  delay(250);
}

But new value is superimposed with old value.I would like to display a variable without blinking. How to resolve this problem?

For my ILI9341 displays, I use the Adafruit TFT library. When printing to the screen, the TFT function allows an optional parameter that represents the font-fill color... When the font-backfround (fill) is the same as the screen background color, the annoying blinking is suppressed.

Ray

You have to use TFT.drawChar. This function plots not only font but also its background. You have to specify foreground and background colors. In order to print text you have to print it char by char using this function.

It is a little bit strange for me that standard functions like TFT.text does not have option of printing background. It even more strange that examples of using this library are using 'blinking techniques'. Nobody wants to have blinking text! So, printing text with background should be, in my opinion, a default option.

Cafeho:
You have to use TFT.drawChar. This function plots not only font but also its background. You have to specify foreground and background colors. In order to print text you have to print it char by char using this function.

Rubbish. Read mrburnette’s reply i.e. use

     tft.setTextColor(YELLOW, RED);     //yellow text on a red background

If you add a trailing space, it will ensure that you do not get left with previous digits when you overwrite a 3-digit number with a 2-digit number.

If you want to draw transparent text, use the other version of setTextColor()

David.

Hello,

Thanks Rob for pointing that out.

the blinking stops,

but how does this work if you want to trigger the tft on different voltage inputs with different background colors?without the blinking?

I am lacking programming skills.

what I want to do is the following:

Voltage input=0V Yellow Screen with a large 0 in the center wait for input signal
Voltage input=1.5V Red Screen with a large 1 in the center wait for input signal
Voltage input=3.3V Blue Screen with a large 2 in the center wait for input signal

then for the experiment someone hast to press a button a red or a blue one.

from this ill send 1 signal with an opamp back to the pc to see if someone pressed a button.

I know that if you create a function and call it in the void loop you can switch things on and off. do I require to use pointers? its been a long time ago that I did programming.

help would be greatly appreciated.

sincerely yours

Bastiaan

sketch_jun03a.ino (1.42 KB)

Sit down with pencil, paper and a nice cup of tea.

Design and draw a flowchart of what you want to do.

Write code for each block in your flowchart.

If you have a problem, post your flowchart and code. Ask a specific question about a specific block in your flowchart/code.

A photo of your pencil flowchart is fine. A neat diagram is fine. A numbered list of steps written in English is fine too. Make sure that you quote which step number you are jumping to in a conditional block.

David.

If you look in the "Adafruit_GFX.cpp" you will see the following.

void Adafruit_GFX::setTextColor(uint16_t c) {
 // For 'transparent' background, we'll set the bg 
 // to the same as fg instead of using a flag
 textcolor = textbgcolor = c;
}

void Adafruit_GFX::setTextColor(uint16_t c, uint16_t b) {
 textcolor   = c;
 textbgcolor = b; 
}

If you only want to Draw the Character with a transparent background meaning you only write the character setTextColor in the prescribed pixels changing none of the surrounding pixels in the character block defined by x, y, setTextSize.

TFT.setTextColor(GREEN); //With Transparent Text Background not updating surrounding pixels.

If you want to Draw the Character with your background color, replace app pixels in the character block defined by x, y, setTextSize with your chosen text color and your background to be the same as your chosen background. This will overwrite all pixels with old character that are no longer used with the background color all at the same time preventing mess of pixels, and character flashing.

TFT.setTextColor.setTextColor(GREEN, BLACK); //With Text Background Color updating surrounding pixels.