Go Down

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

gokulakannan

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.
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:
  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?

robtillaart

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;
  }
  delay(250);
}
Rob Tillaart

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

mrburnette

Quote
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

Go Up