The best way to prevent blinking is to only paint the part of the screen that needs updating. Keep the previous value displayed in memory, if there is no change, don’t update the display. Don’t erase everything to repaint the screen, target only the element that really needs to be updated
Every time though loop, you are displaying "No Object", then if sensorState is LOW erasing that and displaying sensval. There is apparently no reason to display "No Object" unless sensorState is HIGH. Also see reply #2, there is no need to constantly erase and re-display the exact same data.
First, get the setRotation out of loop and put that in setup - that may be causing some flickering, and I do not see anywhere that you are changing the rotation to anything other than 3.
Next, only display "No Object" when sensorState changes from LOW to HIGH, there is no reason to repeatedly display the same thing over and over again.
When sensorState is LOW, only update the display when the value of sensval changes, or sensorState has changed from HIGH to LOW.
hi. i try this and the flicker/wink/ blink is gone but there is another problem. first tft print "No Object" when the sensorState is HIGH the sensval also printed so they both printed. how to switch between "No object" and printing sensval over sensorstate change. thank you
// Include application, user and local libraries
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <Wire.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
#define ILI9341_DRIVER
#define _cs 5 // goes to TFT CS
#define _dc 2 // goes to TFT DC
#define _mosi 23 // goes to TFT MOSI
#define _sclk 18 // goes to TFT SCK/CLK
#define _rst 4 // goes to TFT RESET
//#define _miso // Not connected
#define pinIR 34 // goes to TFT RESET
int param = 4;
Adafruit_ILI9341 tft = Adafruit_ILI9341(_cs, _dc, _rst);
String s;
void setup() {
Serial.begin(115200);
tft.begin();
uint8_t x = tft.readcommand8(ILI9341_RDMODE);
mlx.begin();
pinMode(pinIR, INPUT);
tft.setRotation(3);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_MAGENTA);
}
void loop() {
int sensorState = digitalRead(pinIR);
float s = mlx.readObjectTempC();
int sensval = s + param;
if (sensorState == LOW) {
tft.setCursor(10, 3);
tft.setTextSize(22);
tft.setCursor(18, 18);
tft.println( sensval);
tft.setTextSize(5);
tft.setCursor(280, 2);
tft.println('o');
}
if(sensorState == HIGH){
tft.setCursor(15, 3);
tft.setTextSize(6);
tft.println("No Object" );
}
}
you erase what you had written previously (possibly just writing the same text at the same position using the background color, or getting the bounding box for the text you want to erase and paint a rectangle with the background color there) and then write the new text
give it a try. update your code so that the loop remembers the previous state
that will let you compare the current calculated state with what is on screen and decide if you need to repaint or not
hi brother i try this code and works, but after several times (less than 30 tft.print(); occured ) the screen turn to white. would you like to analyze my code. thank you
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <Wire.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
#define ILI9341_DRIVER
#define _cs 5 // goes to TFT CS
#define _dc 2 // goes to TFT DC
#define _mosi 23 // goes to TFT MOSI
#define _sclk 18 // goes to TFT SCK/CLK
#define _rst 4 // goes to TFT RESET
//#define _miso // Not connected
#define pinIR 34 // goes to TFT RESET
int param = 4;
#define _cs 5 // goes to TFT CS
#define _dc 2 // goes to TFT DC
#define _mosi 23 // goes to TFT MOSI
#define _sclk 18 // goes to TFT SCK/CLK
#define _rst 4 // goes to TFT RESET
#define pinIR 34 // goes to TFT RESET
Adafruit_ILI9341 tft = Adafruit_ILI9341(_cs, _dc, _rst);
boolean prinT = false;
float s;
void setup()
{
Serial.begin(115200);
Wire.begin(); // join I2C bus
tft.begin();
tft.setRotation(3);
mlx.begin();
pinMode(pinIR, INPUT);
}
void loop(){
int sensorState = digitalRead(pinIR);
if (sensorState == LOW && prinT == true)
{
float s = mlx.readObjectTempC();
int sensval = s + param;
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_MAGENTA);
tft.setCursor(10, 3);
tft.setTextSize(22);
tft.setCursor(18, 18);
tft.print( sensval);
tft.setTextSize(5);
tft.setCursor(280, 2);
tft.println('o');
prinT = false;
Serial.print(sensval);
}
if(sensorState == HIGH && prinT == false)
{
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_MAGENTA);
tft.setCursor(15, 3);
tft.setTextSize(5);
tft.print("No Object");
prinT = true;
}
}
There is nothing painting the screen white in the code that I see - so might be a hardware bug (poor wiring, etc), a bug in the library.
You keep erasing the screen more often that needed though - you aloud remember what’s on screen and only repaint the screen when that value has changed