LED (lv_led)¶
概述¶
LED 是一个类似矩形(或圆形)的对象,其亮度可以调整。亮度较低时,LED 的颜色会变暗。
部件和样式¶
LED 只有一个主要部件,称为 LV_LED_PART_MAIN,它使用所有典型的背景样式属性。
用法¶
颜色¶
可以使用 lv_led_set_color(led, lv_color_hex(0xff0080)) 设置 LED 的颜色。
此颜色将用作背景颜色、边框颜色和阴影颜色。
亮度¶
可以使用 lv_led_set_bright(led, bright) 设置亮度。亮度应在 0(最暗)到 255(最亮)之间。
切换¶
使用 lv_led_on(led) 和 lv_led_off(led) 将亮度设置为预定义的打开或关闭值。lv_led_toggle(led) 在打开和关闭状态之间切换。
事件¶
LV_EVENT_DRAW_PART_BEGIN和LV_EVENT_DRAW_PART_END会针对以下类型发送:LV_LED_DRAW_PART_RECTANGLE主矩形。LV_OBJ_DRAW_PART_RECTANGLE不会由基础对象发送。part:LV_PART_MAINrect_dscdraw_area: 矩形的区域
也可以查看 基础对象 的事件。
了解更多关于事件的信息。
示例¶
LED with custom style¶
C code
GitHub#include "../../lv_examples.h"
#if LV_USE_LED && LV_BUILD_EXAMPLES
/**
* Create LED's with different brightness and color
*/
void lv_example_led_1(void)
{
/*Create a LED and switch it OFF*/
lv_obj_t * led1 = lv_led_create(lv_scr_act());
lv_obj_align(led1, LV_ALIGN_CENTER, -80, 0);
lv_led_off(led1);
/*Copy the previous LED and set a brightness*/
lv_obj_t * led2 = lv_led_create(lv_scr_act());
lv_obj_align(led2, LV_ALIGN_CENTER, 0, 0);
lv_led_set_brightness(led2, 150);
lv_led_set_color(led2, lv_palette_main(LV_PALETTE_RED));
/*Copy the previous LED and switch it ON*/
lv_obj_t * led3 = lv_led_create(lv_scr_act());
lv_obj_align(led3, LV_ALIGN_CENTER, 80, 0);
lv_led_on(led3);
}
#endif
#
# Create LED's with different brightness and color
#
# Create a LED and switch it OFF
led1 = lv.led(lv.scr_act())
led1.align(lv.ALIGN.CENTER, -80, 0)
led1.off()
# Copy the previous LED and set a brightness
led2 = lv.led(lv.scr_act())
led2.align(lv.ALIGN.CENTER, 0, 0)
led2.set_brightness(150)
led2.set_color(lv.palette_main(lv.PALETTE.RED))
# Copy the previous LED and switch it ON
led3 = lv.led(lv.scr_act())
led3.align(lv.ALIGN.CENTER, 80, 0)
led3.on()
API¶
Enums
Functions
-
lv_obj_t *
lv_led_create(lv_obj_t *parent)¶ Create a led object
- Parameters
parent -- pointer to an object, it will be the parent of the new led
- Returns
pointer to the created led
-
void
lv_led_set_color(lv_obj_t *led, lv_color_t color)¶ Set the color of the LED
- Parameters
led -- pointer to a LED object
color -- the color of the LED
-
void
lv_led_set_brightness(lv_obj_t *led, uint8_t bright)¶ Set the brightness of a LED object
- Parameters
led -- pointer to a LED object
bright -- LV_LED_BRIGHT_MIN (max. dark) ... LV_LED_BRIGHT_MAX (max. light)
Variables
-
const lv_obj_class_t
lv_led_class¶
-
struct
lv_led_t¶