<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How To Overwrite Text Without Flash?]]></title><description><![CDATA[<p dir="auto">I'm working on a timer application. It runs fine, but when the timer updates there is a distinct (and bothersome) flash. It's as if the process fills the space used by the text with the background color, and then writes the text on top of that. This is the code fragment.</p>
<p dir="auto">void display_mmss(uint8_t mm, uint8_t ss, uint16_t fc, uint16_t bc)<br />
{<br />
char timeStr[6] = {'0', '0', ':', '0', '0', '\0'};</p>
<p dir="auto">timeStr[0] = char('0' + (mm / 10));<br />
timeStr[1] = char('0' + (mm % 10));<br />
timeStr[3] = char('0' + (ss / 10));<br />
timeStr[4] = char('0' + (ss % 10));</p>
<p dir="auto">m5.lcd.setTextColor(fc, bc);<br />
m5.lcd.setTextDatum(CC_DATUM);<br />
m5.lcd.setFreeFont(&amp;Digital7Mono65pt7b);<br />
m5.lcd.drawString(timeStr, 160, 120);<br />
}</p>
<p dir="auto">(My code is properly indented -- this forum doesn't seem to allow for that)</p>
]]></description><link>https://community.m5stack.com/topic/730/how-to-overwrite-text-without-flash</link><generator>RSS for Node</generator><lastBuildDate>Thu, 30 Apr 2026 17:41:15 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/730.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 04 Mar 2019 17:07:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How To Overwrite Text Without Flash? on Wed, 10 Jul 2024 18:20:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonnymac" aria-label="Profile: JonnyMac">@<bdi>JonnyMac</bdi></a> Hi Jonny, your post is quite old however I want to share with you (and anyone else) my experience.<br />
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).<br />
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:</p>
<p dir="auto">See especially the following set of lines of code:</p>
<pre><code> int elapsedSecsMod = elapsed_secs_t % 10;
 if (elapsedSecsMod &gt; 0)
   elapsedSecs_shown = false;  // reset flag
 
 if (start || (!elapsedSecs_shown &amp;&amp; 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
 }
</code></pre>
<p dir="auto">Below the lines above in the total example:</p>
<pre><code>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) &gt; 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 &gt; 0)
    elapsedSecs_shown = false;  // reset flag
  
  if (start || (!elapsedSecs_shown &amp;&amp; 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;
}
</code></pre>
]]></description><link>https://community.m5stack.com/post/25813</link><guid isPermaLink="true">https://community.m5stack.com/post/25813</guid><dc:creator><![CDATA[Paulskpt]]></dc:creator><pubDate>Wed, 10 Jul 2024 18:20:05 GMT</pubDate></item><item><title><![CDATA[Reply to How To Overwrite Text Without Flash? on Tue, 19 Mar 2019 05:58:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonnymac" aria-label="Profile: jonnymac">@<bdi>jonnymac</bdi></a> Partial refresh the text.</p>
<p dir="auto">e.g.</p>
<pre><code class="language-arduino">m5.lcd.fillRect(x,y,h,w,backgroundcolor);//erase partial place for updating data
m5.lcd.drawString("....");//display your Time-varying text
</code></pre>
]]></description><link>https://community.m5stack.com/post/3353</link><guid isPermaLink="true">https://community.m5stack.com/post/3353</guid><dc:creator><![CDATA[m5-docs]]></dc:creator><pubDate>Tue, 19 Mar 2019 05:58:41 GMT</pubDate></item></channel></rss>