I am using the normal demo button code:
static void btn_event_cb(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * btn = lv_event_get_target(e);
if(code == LV_EVENT_CLICKED) {
cnt++;
/*Get the first child of the button which is the label and change its text*/
lv_obj_t * label = lv_obj_get_child(btn, 0);
lv_label_set_text_fmt(label, "Button: %d", cnt);
}
}
Also, i have a working label as following (inside setup part):
lv_obj_t * label1 = lv_label_create( lv_scr_act() );
lv_label_set_text(label1, "test");
lv_obj_set_pos(label1, 20, 20);
And i have moved the variable “static uint8_t cnt = 0;” outside void in order to make it global, so i have it as:
uint8_t cnt = 0;
Finally, what i want to do is to update label1 with the value of “cnt” when button is pressed.
I have tested many things as adding:
lv_label_set_text_fmt(label1, cnt);
or
lv_obj_t * label1_ = lv_obj_get_child(label1, 0);
lv_label_set_text_fmt(label1_, cnt);
The button is being updated but the label does not.
So, what am i doing wrong?
Any suggestions?
Thank you in advance!