lvgl / docs_old

DEPRECATED: Documentation for LVGL is now located in the main repository: https://github.com/lvgl/lvgl
https://docs.lvgl.io/
42 stars 73 forks source link

Issue About the Label Object #192

Closed Genkyang closed 3 years ago

Genkyang commented 3 years ago

I have a question about the using of label widget in Arduino. I created a label that uses the following code in "setup" function: lv_obj_t label1 = lv_label_create(scr1, NULL); // yeah I created a screen and acted it. lv_label_set_long_mode(label1, LV_LABEL_LONG_BREAK); /Break the long lines/ lv_label_set_align(label1, LV_LABEL_ALIGN_RIGHT); /Center aligned lines*/ lv_label_set_text(label1, temperchar); lv_obj_add_style(label1, LV_LABEL_PART_MAIN, &label_style); lv_obj_set_width(label1, 150); lv_obj_align(label1, NULL, LV_ALIGN_CENTER, -10, 80);

And then, I want to change the text using "lv_label_set_text(label1, temperchar);" in the "Loop" function, but the debug program says that I didn't define the "label1".

I tried to create the label behind the "setup" function using "lv_obj_t * label1 = lv_label_create(scr1, NULL); ". However, when I upload my program to the ESP32 board, it has frozen, and the serial said the following:

rst:0x10 (RTCWDT_RTC_RESET),boot:0x12 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:1 load:0x3fff0018,len:4 load:0x3fff001c,len:1044 load:0x40078000,len:10124 load:0x40080400,len:5856 entry 0x400806a8

I don't know how to solve this problem. I hope you can help me with this problem.

embeddedt commented 3 years ago

You need to declare label1 as a global variable, initialize it in the setup function without redeclaring it, and then use it in the loop function. I suggest reading up on global variables in C.

Genkyang commented 3 years ago

You need to declare label1 as a global variable, initialize it in the setup function without redeclaring it, and then use it in the loop function. I suggest reading up on global variables in C.

I did try to declare "label1" as a global variable, but the ESP32 was not working as I expected. As I mentioned, the ESP32 has frozen.

embeddedt commented 3 years ago

Did you then redeclare it inside the setup function? That will shadow it and the global will not be changed. You need to ensure you are just initializing it, not redeclaring it.

Genkyang commented 3 years ago

Thanks for your help! I found the problem and solved it! As you mentioned, I redeclared the label in the setup function.