Update Label Text depending upon a boolean

What do you want to achieve?

I wish to update the text on a Label to either Yes or No, depending upon a Global Boolean created in setup1()

What have you tried so far?

I have tried to use ChatGPT and Google to find solutions but the returns are unhelpful to say the least.

Code to reproduce

I am using EEZ Studio 0.24.0 Flow to design the Screens and Labels.
I am using Arduino IDE 2.3.6 (Don’t understand how to setup VSCODE or PLatform.io)
The Global Variables are created using EEZ Studio Flow (Native)

Screenshot and/or video

Environment

  • MCU/MPU/Board: Waveshare Pico 2 LCD Touch 2350 2,8"
  • LVGL version: 9.3

Courtesy

Thank you for any guidance.
I cannot spend too long on my laptop as I am almost blind. :sunglasses:

Hi. You can achieve this using observer and subject feature of LVGL. Take a look at the documentation here: How to Use - LVGL 9.4 documentation

Here is a small example:

Have this globally:

lv_subject_t subject_yesno;
static lv_obj_t * label;
static void subject_cb(lv_observer_t * observer, lv_subject_t * subject)
{
    int v = lv_subject_get_int(subject);
    lv_label_set_text(label, (v == 1) ? "Yes" : "No");
}

Then in main, after LVGL is fully initialized, you can have this:

lv_subject_init_int(&subject_yesno, 0);
label = lv_label_create(lv_screen_active());
lv_subject_add_observer(&subject_yesno, subject_cb, NULL);
lv_subject_set_int(&subject_yesno, 1);

You will end up with a label showing “Yes”.

You can call lv_subject_set_int(&subject_yesno, 0/1); anywhere in the code to update the label.

Unfortunately I’m not exactly sure how to achieve that with EEZ Studio. If you can edit the code you probably can do it as I showed. Same for Arduino IDE.

Thank you for your excellent explanation.
I will certainly give it a try.
Kind regards,
jB :sunglasses: