🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    How To Overwrite Text Without Flash?

    Arduino
    3
    3
    4.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      JonnyMac
      last edited by JonnyMac

      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.

      void display_mmss(uint8_t mm, uint8_t ss, uint16_t fc, uint16_t bc)
      {
      char timeStr[6] = {'0', '0', ':', '0', '0', '\0'};

      timeStr[0] = char('0' + (mm / 10));
      timeStr[1] = char('0' + (mm % 10));
      timeStr[3] = char('0' + (ss / 10));
      timeStr[4] = char('0' + (ss % 10));

      m5.lcd.setTextColor(fc, bc);
      m5.lcd.setTextDatum(CC_DATUM);
      m5.lcd.setFreeFont(&Digital7Mono65pt7b);
      m5.lcd.drawString(timeStr, 160, 120);
      }

      (My code is properly indented -- this forum doesn't seem to allow for that)

      m5-docsM PaulskptP 2 Replies Last reply Reply Quote 0
      • m5-docsM
        m5-docs @JonnyMac
        last edited by

        @jonnymac Partial refresh the text.

        e.g.

        m5.lcd.fillRect(x,y,h,w,backgroundcolor);//erase partial place for updating data
        m5.lcd.drawString("....");//display your Time-varying text
        

        M5Stack documentation URL

        https://docs.m5stack.com

        1 Reply Last reply Reply Quote 0
        • PaulskptP
          Paulskpt @JonnyMac
          last edited by Paulskpt

          @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;
          }
          

          Coding keeps your mind going

          1 Reply Last reply Reply Quote 0
          • First post
            Last post