How to blank/wipe the screen?

I am trying to program an Arduino Giga Display. I am using LVGL for most of my project, though I do use GigaDisplay_GFX for part of my code right at the start. I am trying to wipe the screen (i.e., go completely white) so that I can show an error message if someone doesn't enter a value then reload the particular menu screen. However, I can't get the screen to blank, and I can't get the error message to show up (it simply shows up as TEXT over the existing screen instead of the error message, but with the right size and alignment). Any ideas about how to fix this?

This is the relevant section of code:

  // Label for error message
  lv_obj_t * label_error_message_value = lv_label_create(lv_scr_act());
  lv_obj_set_style_text_font(label_error_message_value, &lv_font_montserrat_30, LV_PART_MAIN | LV_STATE_DEFAULT);
  lv_obj_align(label_error_message_value, LV_ALIGN_CENTER, 0, 0);

  // Validating entry
  if (value == 0){
    DisplayGFX.fillScreen(0xFFFF);
    lv_refr_now(NULL);
    lv_label_set_text(label_error_message_value, "Error: value cannot equal 0.");
    lv_task_handler();
    Serial.println("Error: value cannot equal 0.");
    delay(1500);
    free_number_text_area();
    enter_numbers();
    return;
  }

I'm trying different options, but nothing seems to work. Any suggestions?

I was able to get the screen to blank finally with this sequence:

  if (value == 0){
    DisplayGFX.fillScreen(0xFFFF);
    lv_obj_clean(lv_scr_act());
    lv_refr_now(NULL); // Force immediate screen refresh
    lv_label_set_text(label_error_message_value, "Error: value cannot equal 0.");
    lv_refr_now(NULL);
    Serial.println("Error: value cannot equal 0.");
    delay(1500);
    free_number_text_area();
    enter_numbers();
    return;              // Exit to avoid further execution
  }

But now the text isn't showing up at all.

I have solved a similar task using the messagebox widget (lv_msgbox) in lvgl instead of using only a label. The messagebox widget has an overlay built in that covers the background when the message box shows. You can adjust that 'overlay' using the usual lvgl commands (create style, change bg color, opacity etc.). How this is done depends on the version of lvgl you are using.

The nice thing about the message box is that you can keep the close button, so the user needs to close the message actively. You can also load dynamic text messages depending on the error, which is what I am doing in my project.

I don't include code examples here since the implementation depends on your lvgl version. Different versions access the messagebox background differently. Here is the link to the widget example in lvgl 8.3 which I am using:

1 Like