I’m using Arduino IDE to program my sensors and lvgl. How to display the current data to a label? and update each time
Hi @Ryan_Gania,
I am unfamiliar with Arduino so this is just a general method using C, you may have to tweak things for the Arduino environment.
You can deliver your sensor data to a static or global variable.
Create a label with a static or global pointer, place it where you want it on your display.
Create a lv_task to periodically update the label
For example:
static int32_t sensor_data = 123;
static lv_obj_t * my_sensor_label;
void my_label_update_task(lv_task_t * task)
{
/*Use the user_data*/
int32_t * user_data = task->user_data;
char * buf[40];
/*Update label*/
sprintf( buf, "My Sensor Data: %ld", *user_data);
lv_label_set_text(my_sensor_label, buf);
}
...
/* Initialisation code */
/*Create Label and set position*/
my_sensor_label = lv_label_create(lv_scr_act(), NULL);
lv_obj_align(my_sensor_label, NULL, LV_ALIGN_CENTER, 0, 0);
lv_label_set_text(my_sensor_label, ""); /* Clear initial default text */
/*Create Task and have it update every 1000 ms*/
lv_task_t * task = lv_task_create(my_update_label_task, 1000, LV_TASK_PRIO_LOW, &sensor_data);
Hope this helps,
Kind Regards,
Pete
Solved this problem! Thanks! Another question, Can a Table Widget be scrollable?
You can create it as a child of a page.
Is this correct?
lv_obj_t * table_page = lv_page_create(lv_scr_act(), NULL);
lv_obj_set_size(table_page, 320, 240);
ship_view_table = lv_table_create(table_page, NULL);
lv_table_set_col_cnt(ship_view_table, 4);
lv_table_set_row_cnt(ship_view_table, 100);
Yes; I think that will work.
Call lv_obj_set_click(table, false)
. Maybe the table is capturing the input events.
It worked! Thank you so much!
I have a last question. How to fit the table column contents to the screen?