How to give delay

Hello everyone ,

I want to print some data on screen on boot up time for some seconds says 3 seconds and then want to fresh screen and print normal data on screen, How to achieve this ,i have tried using sleep or usleep method before calling while(1) ,but not working as it should work.My code flow is like below.

void display_boot_data(void)
{
static lv_obj_t *label_version1;
static lv_style_t style;
int i =0;
lv_obj_t * scr = lv_disp_get_scr_act(NULL);

puts("In thread display\n") ;
lv_style_copy(&style, &lv_style_plain);
style.text.color = LV_COLOR_BLUE;
style.text.font = &lv_font_roboto_28 ;

label_version1 = lv_label_create(scr, NULL) ; 

lv_label_set_style(label_version1, LV_LABEL_STYLE_MAIN, &style);

lv_label_set_static_text(label_version1, "Hello world") ;

lv_obj_align(label_version1, NULL, LV_ALIGN_CENTER, 0, 0);



usleep(3000);
lv_label_set_static_text(label_version1, "");
lv_label_set_static_text(label_version2, "");
lv_obj_del(label_version1);

lv_obj_clean(scr);

printf("After 3 sends finished\n") ;

}

int main()
{
while(1) {

	 lv_tick_inc(5);
	lv_task_handler();
            usleep(5000);
    }

}

Please suggest your opinion on this code . Any give me your valuable suggestion on how to achieve this feature.

After the second floor elder brother’s suggestion was modified.
After printing the code of display information, you can create a task, set it as 3S to call once, put your normal display interface into the task to start, Call lv_task_once() after the task creation function.
The above text is from youdao translation

lv_task_t* task;

void boot_task(lv_task_t* task)
{
	printf("Boot success");
	main_window();
	
	//lv_task_del(task);
}

int main(int argc, char** argv)
{
	//The code to display the startup information is written here

	task = lv_task_create(boot_task, 3000, LV_TASK_PRIO_HIGHEST, NULL);
	lv_task_once(task);

	while (1) 
	{
		lv_task_handler();
	}
}

Technically I think you should use lv_task_once(task) after calling lv_task_create; that way you don’t need to delete the task inside its callback. Otherwise, this is the correct approach! :+1:

2 Likes

Thank you very much for your answer, I am still a beginner, did not know there is this function, but now know, thank you.

Thanks Marjin for your suggestion. It worked…

Thank you for your valuable input on this …