Update Label. Not working

Update Label.

Newest Master.
I use an ESP32 with an 2.8 zoll dp over spi
And the Arduino IDE

What I Found

Docu link:

Github issues.

Forum Link:
I cant use Links…


I cant Update the label. i found 3 ways. and i want to use the way with tasks.
the solution with tasks from docu:

#include "../../../lv_examples.h"

static void text_changer(lv_task_t * t);

lv_obj_t * labels[3];

 * Create three labels to demonstrate the alignments.
void lv_ex_label_3(void)
    /*`lv_label_set_align` is not required to align the object itslef.
     * It's used only when the text has multiple lines*/

    /* Create a label on the top.
     * No additional alignment so it will be the reference*/
    labels[0] = lv_label_create(lv_scr_act(), NULL);
    lv_obj_align(labels[0], NULL, LV_ALIGN_IN_TOP_MID, 0, 5);
    lv_label_set_align(labels[0], LV_LABEL_ALIGN_CENTER);

    /* Create a label in the middle.
     * `lv_obj_align` will be called every time the text changes
     * to keep the middle position */
    labels[1] = lv_label_create(lv_scr_act(), NULL);
    lv_obj_align(labels[1], NULL, LV_ALIGN_CENTER, 0, 0);
    lv_label_set_align(labels[1], LV_LABEL_ALIGN_CENTER);

    /* Create a label in the bottom.
     * Enable auto realign. */
    labels[2] = lv_label_create(lv_scr_act(), NULL);
    lv_obj_set_auto_realign(labels[2], true);
    lv_obj_align(labels[2], NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -5);
    lv_label_set_align(labels[2], LV_LABEL_ALIGN_CENTER);

    lv_task_t * t = lv_task_create(text_changer, 1000, LV_TASK_PRIO_MID, NULL);

static void text_changer(lv_task_t * t)
    const char * texts[] = {"Text", "A very long text", "A text with\nmultiple\nlines", NULL};
    static uint8_t i = 0;

    lv_label_set_text(labels[0], texts[i]);
    lv_label_set_text(labels[1], texts[i]);
    lv_label_set_text(labels[2], texts[i]);

    /*Manually realaign `labels[1]`*/
    lv_obj_align(labels[1], NULL, LV_ALIGN_CENTER, 0, 0);

    if(texts[i] == NULL) i = 0;


the second solution is:

  1. set an event function for the label
  2. In LV_EVENT_REFRESH set the text as you need by using the variables you need
  3. Send an LV_EVENT_REFRESH manually with lv_event_send(label, LV_EVENT_REFRESH, NULL); when the label needs to be refreshed

and the third: (but i dont now to use it correctly)

int my_val = <whatever>;
lv_label_set_text_fmt(label, "%d", my_val);

What do you want to achieve?

Updating Time on the Interface.

What have you tried so far?

void loop(void) {
  lv_task_handler(); /* let the GUI do its work */
void my_task(lv_task_t * task);

void lv_mainmenu(void)
  lv_obj_t * cont1mainmenu = lv_cont_create(lv_scr_act(), NULL);
  lv_obj_set_height(cont1mainmenu, 0.10 * dphigh); // set height
  lv_cont_set_fit2(cont1mainmenu, LV_FIT_MAX,0);
  lv_obj_align(cont1mainmenu, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
  lv_obj_t * ltimemainmenu;
  ltimemainmenu = lv_label_create(cont1mainmenu, NULL);
  lv_label_set_text(ltimemainmenu, timePrint("%H:%M", 6).c_str());

  lv_task_t * task = lv_task_create(my_task, 10, LV_TASK_PRIO_LOWEST, NULL);
lv_obj_t * ltimemainmenu;
void my_task(lv_task_t * task)
  Serial.println(timePrint("%H:%M:%S", 10) + " : ltest");
  lv_label_set_text(ltimemainmenu, timePrint("%H:%M", 6).c_str());

If i use 0 ms period the touch is working but my_task came only one time.
if i use more then 1 ms is the same issue but without working touch.

my fault was the lv_obj_t * ltimemainmenu; in lv_mainmenu(void).
after deleting it. it works.

For the future, I would strongly recommend finding a way to turn on compiler warnings. All modern C compilers will usually warn you of variable shadowing issues like this, which will save you a lot of debugging effort. :wink:

i dont have deactivate warnings or something. i use the standard arduino ide but if i found a way to activate more warnings i will be activate it.

You can find it under File->Preferences; there should be a “Compiler warnings” option there. I would recommend setting it to More at the very least. Warnings can be annoying if you are trying to rapidly prototype, but they save you a LOT of grief when debugging.

1 Like

i set it from standard to all. Thank you.