I am displaying date, time, and a voltage level on a TFT screen, using the MCUFRIEND_kbv library. At this point, the whole screen refreshes with the relevant data every 5 seconds.
However, I only want to reprint the voltage level and time if and when it changes. Basically, I want to refresh different parts of the screen at different times.
#include <virtuabotixRTC.h> //Libraries needed
#include "Adafruit_GFX.h" // Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#define BLACK 0x0000 /* 0, 0, 0 */
#define LIGHTGREY 0xC618 /* 192, 192, 192 */
#define WHITE 0xFFFF /* 255, 255, 255 */
virtuabotixRTC myRTC(6, 7, 8);
void setup() {
Serial.begin(9600);
tft.reset();
tft.begin(0x9488);
tft.setRotation(1);
//myRTC.setDS1302Time(00, 05, 11, 05, 25, 06, 2022);
}
void loop() {
tft.fillScreen(BLACK);
myRTC.updateTime();
tft.drawLine(0, 27, 480, 27, LIGHTGREY);
tft.drawLine(0, 28, 480, 28, LIGHTGREY);
tft.drawLine(240, 0, 240, 28, LIGHTGREY);
tft.drawLine(241, 0, 241, 28, LIGHTGREY);
tft.setTextSize(3);
tft.setCursor(5, 3);
if (myRTC.dayofmonth < 10) {
tft.print("0");
tft.print(myRTC.dayofmonth);
}
else {
tft.print(myRTC.dayofmonth);
}
tft.print("/");
if (myRTC.month < 10) {
tft.print("0");
tft.print(myRTC.month);
}
else {
tft.print(myRTC.month);
}
tft.print("/");
tft.print(myRTC.year);
tft.setCursor(246, 3);
if (myRTC.hours < 10) {
tft.print("0");
tft.print(myRTC.hours);
}
else {
tft.print(myRTC.hours);
}
tft.print(":");
if (myRTC.minutes < 10) {
tft.print("0");
tft.print(myRTC.minutes);
}
else {
tft.print(myRTC.minutes);
}
int sensor = analogRead(A1);
float voltage = (sensor * 5.0) / 1023;
tft.setTextSize(3);
tft.setCursor(3, 33);
tft.print(voltage);
delay(5000);
}
Does anyone know how to achieve this?




