Hello,
I have a question regarding eliminating the flicker caused when a tft screen is refreshed. In my case, the screen displays a clock, and flickers with each second. I have tried to solve this issue myself with a solution I found here on the Adafruit forums, but could do with some help understanding the solution, and getting it to work with my sketch as I have been having some issues with that.
This thread gave me the hint "you may need to set up a fixed-size string and fill it with spaces each time before sprintf()ing into it...but this is an in-memory operation and would go very quickly, vs. accessing the display.", but I was not sure how to implement that. https://forums.adafruit.com/viewtopic.php?f=47&t=29600
This thread seemed to solve the issue via the same method "i wrote a small "Format" function to pad the data with spaces. That way the total digit amount is the same, so painting the background black works in all cases." https://forums.adafruit.com/viewtopic.php?f=25&t=83132
I attempted to implement that solution myself, but get the error: "cannot convert 'char*' to 'double' for argument '1' to 'String Format(double, int, int)'". I am someone may be able to help me better understand how to modify the solution to function with my sketch below. The 'String Format' function below is the solution from the above link.
void loop () {
DateTime now = rtc.now();
tft.setTextColor(GREY);
tft.setTextSize(2);
tft.fillRect(10, 15, 140, 19, BLACK);
tft.setCursor(10, 15);
tft.print(daysOfTheWeek[now.dayOfTheWeek()]);
sprintf(dateBuffer," %02u/%02u/%04u %02u:%02u:%02u ",now.day(),now.month(),now.year(),now.hour(),now.minute(),now.second());
tft.fillRect(225, 15, 250, 19, BLACK);
tft.setCursor(225, 15);
tft.print(Format(dateBuffer));
delay(1000);
}
String Format(double val, int dec, int dig ) {
int addpad = 0;
char sbuf[26]; // your call on the size
String condata = dtostrf(val, dec, dig, sbuf);
int slen = condata.length();
for (addpad = 1; addpad <= dec + dig - slen; addpad++){
condata = " " + condata;
}
return (condata);
}