Updating the Label in a loop


Hello. There is a button with a label, when clicked, an event is called. There is a loop in the event. I want to update the label of the button every iteration, but the label is only updated when the event ends

What MCU/Processor/Board and compiler are you using?


What LVGL version are you using?


What do you want to achieve?

Update the button label every iteration

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

static void event_bt_unpair(lv_event_t * e)
	lv_event_code_t code = lv_event_get_code(e);
	lv_obj_t * obj = lv_event_get_target(e);
	lv_obj_t * lb_obj = lv_obj_get_child(obj, 0);

		for (int i = 0; i < sensor_count(); i++)
			lv_label_set_text_fmt(lb_obj, "%d", i);
			lv_obj_t * child = lv_obj_get_child(cont_seat_unpair, i);

			  if(lv_obj_get_state(child) & LV_STATE_CHECKED)

Normally the redrawing is periodically executed in lv_timer_handler but a long blocking process can prevent the call of lv_timer_handler temporarily. In this case if the GUI is updated in the process (e.g. a label text) you can call the function lv_refr_now when the screen should be updated.

void lv_refr_now(lv_disp_t * disp)
  • Redraw the invalidated areas now.
  • @param disp pointer to display to refresh. NULL to refresh all displays.

Try to add this line after updating the label(s):

  lv_refr_now(NULL);         /* Will call our disp_drv.disp_flush function */

Thanks. It really helped