Go Down

Topic: Display a variable in TFT Screen without blink (Read 146 times) previous topic - next topic


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


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.
Code: [Select]

#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:

  // 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
  // set the font size
  // 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

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
  // print the sensor value
  TFTscreen.text(sensorPrintout, 0, 20);
  // wait for a moment
  // erase the text you just wrote
  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.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.

Code: [Select]

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

    // write x in black

  // remember last value
    prevX = x;
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


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.


Go Up