@JonnyMac Hi Jonny, your post is quite old however I want to share with you (and anyone else) my experience.
I had the same "flash" or "flickering" while updating data on the M5Stack Core display. In my case update of elapsed seconds (every 10 seconds).
It was caused by the fact that quite a bit of redrawing took place in a same second. So I wrote the following lines to prevent redraw in the same second:
See especially the following set of lines of code:
int elapsedSecsMod = elapsed_secs_t % 10;
if (elapsedSecsMod > 0)
elapsedSecs_shown = false; // reset flag
if (start || (!elapsedSecs_shown && elapsedSecsMod == 0)) {
sprintf(charVal, "%6lu", elapsed_secs_t);
disp_nr(120, charVal); // Display elapsed seconds
elapsedSecs_shown = true; // set flag. Prevents value get redrawn many times in the same second
}
Below the lines above in the total example:
unsigned long start_t;
unsigned long curr_t;
unsigned long elapsed_msecs_t;
unsigned long elapsed_secs_t;
unsigned long elapsed_mins_t;
unsigned long elapsed_mins_old_t = 0;
unsigned long interval_t;
int cur_h = 10;
int cur_v = 10;
void setup() {
M5.begin();
M5.Lcd.fillScreen(BLACK);
Serial.begin(115200);
start_t = millis();
M5.Lcd.setCursor(cur_h, cur_v+120);
M5.Lcd.print("Elapsed Secs:");
}
void disp_nr(int v_incr, const char* sNr) {
int cur_h_new = 0;
M5.Lcd.setTextPadding(M5.Lcd.width() - 50);
cur_h_new = 80;
// NOTE: the 4th parameter to M5.Lcd.fillRect() must be at least 14 to cover all the height of a digit of M5.Lcd.setTextSize(2) !!!
M5.Lcd.fillRect(cur_h_new, cur_v + v_incr, 100, 14, BLACK); // erase partial place for updating data
if (strlen(sNr) > 0) {
M5.Lcd.setTextSize(2);
M5.Lcd.drawString(sNr, 100, cur_v + v_incr);
M5.Lcd.setTextSize(1);
}
}
bool start = true;
bool elapsedSecs_shown = false;
void loop() {
char es2[] = "Elapsed Secs: ";
int le = 8;
char charVal[le];
curr_t = millis();
elapsed_msecs_t = curr_t - start_t;
elapsed_secs_t = (long) elapsed_msecs_t / 1000;
elapsed_mins_t = (long) elapsed_secs_t / 60;
int elapsedSecsMod = elapsed_secs_t % 10;
if (elapsedSecsMod > 0)
elapsedSecs_shown = false; // reset flag
if (start || (!elapsedSecs_shown && elapsedSecsMod == 0)) { // Every 10 seconds
sprintf(charVal, "%6lu", elapsed_secs_t);
disp_nr(120, charVal); // Display elapsed seconds
elapsedSecs_shown = true; // set flag. Prevents value get redrawn many times in the same second
}
// [ more code here ]
if (start)
start = false;
}