1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| void demo11() { dht.begin();
static lv_style_t date_time_clock_style; lv_style_reset(&date_time_clock_style); lv_style_init(&date_time_clock_style); lv_style_set_radius(&date_time_clock_style, 5); lv_style_set_bg_opa(&date_time_clock_style, LV_OPA_20); lv_style_set_border_width(&date_time_clock_style, 0); lv_style_set_bg_color(&date_time_clock_style, lv_color_white()); lv_style_set_pad_left(&date_time_clock_style, 1); lv_style_set_pad_right(&date_time_clock_style, 1); lv_style_set_pad_top(&date_time_clock_style, 0); lv_style_set_pad_bottom(&date_time_clock_style, 0);
static lv_style_t time_style; lv_style_reset(&time_style); lv_style_init(&time_style); lv_style_set_bg_opa(&time_style, LV_OPA_COVER); lv_style_set_border_width(&time_style, 0); lv_style_set_radius(&time_style, 5); lv_style_set_bg_color(&time_style, lv_palette_main(LV_PALETTE_BLUE)); lv_style_set_pad_left(&time_style, 0); lv_style_set_pad_right(&time_style, 0); lv_style_set_pad_top(&time_style, 0); lv_style_set_pad_bottom(&time_style, 0);
static lv_style_t time_label_style; lv_style_reset(&time_label_style); lv_style_init(&time_label_style); lv_style_set_text_color(&time_label_style, lv_color_white()); lv_style_set_text_font(&time_label_style, &lv_font_montserrat_32); lv_style_set_text_opa(&time_label_style, LV_OPA_COVER); lv_style_set_bg_opa(&time_label_style, LV_OPA_0);
lv_obj_t *dht11_obj = lv_obj_create(lv_scr_act());
lv_obj_set_size(dht11_obj, 320, 150); lv_obj_center(dht11_obj); lv_obj_add_style(dht11_obj, &time_style, LV_STATE_DEFAULT);
static lv_dht11_t lv_dht11 = {0};
lv_dht11.temperature_label = lv_label_create(dht11_obj); lv_obj_add_style(lv_dht11.temperature_label, &time_label_style, LV_STATE_DEFAULT);
lv_dht11.humidity_label = lv_label_create(dht11_obj); lv_obj_add_style(lv_dht11.humidity_label, &time_label_style, LV_STATE_DEFAULT);
lv_obj_align_to(lv_dht11.temperature_label, lv_obj_get_parent(lv_dht11.temperature_label), LV_ALIGN_TOP_MID, 0, 0); lv_obj_align_to(lv_dht11.humidity_label, lv_obj_get_parent(lv_dht11.humidity_label), LV_ALIGN_BOTTOM_MID, 0, 0);
lv_timer_t *task_timer = lv_timer_create(demo11_my_timer, 2000, (void *)&lv_dht11); }
|