LED(指示灯) (lv_led)

Overview(概述)

显示原文

The LEDs are rectangle-like (or circle) Widgets whose brightness can be adjusted. With lower brightness the colors of the LED become darker.


LED(指示灯)是矩形(或圆形)部件。它的亮度可以调节。亮度降低时,LED的颜色会变暗。

Parts and Styles(部分和样式)

显示原文
  • LV_LED_PART_MAIN uses all the typical background style properties.


  • LV_LED_PART_MAIN 它使用所有典型的背景样式属性。

Usage(用法)

Color(颜色)

显示原文

You can set the color of the LED with lv_led_set_color(led, lv_color_hex(0xff0080)). This will be used as background color, border color, and shadow color.


可以使用函数 lv_led_set_color(led, lv_color_hex(0xff0080)) 设置 LED 的颜色。这将用作背景颜色、边框颜色和阴影颜色。

Brightness(亮度)

显示原文

You can set their brightness with lv_led_set_bright(led, bright). The brightness should be between 0 (darkest) and 255 (lightest).


可以使用函数 lv_led_set_bright(led, bright) 设置它们的亮度。亮度范围:0(最暗)- 255(最亮)。

Toggle(切换)

显示原文

Use lv_led_on(led) and lv_led_off(led) to set the brightness to a predefined ON or OFF value. The lv_led_toggle(led) toggles between the ON and OFF state.

You can set custom LED ON and OFF brightness values by defining macros LV_LED_BRIGHT_MAX and LV_LED_BRIGHT_MIN in your project. Their default values are 80 and 255. These too must be in the range [0..255].


使用函数 lv_led_on(led)lv_led_off(led) 将亮度设置为预定义的ON或OFF值。函数:cpp:expr:lv_led_toggle(led) 就像开关,会让led在ON和OFF状态之间切换。

你可以通过在项目中定义宏 LV_LED_BRIGHT_MAXLV_LED_BRIGHT_MIN 来设置自定义的 LED 亮起和熄灭时的亮度值。它们的默认值分别为 80 和 255。这两个值也必须处于 [0..255] 这个取值范围内。 .. _lv_led_events:

Events(事件)

显示原文

No special events are sent by LED Widgets.

Further Reading

Learn more about Base-Widget Events emitted by all Widgets.

Learn more about Events(事件).


LED 部件不会发送特殊事件。

另请参阅 Base-Widget Events 的事件。

了解有关 Events(事件) 的更多内容。

Keys(按键)

显示原文

No Keys are processed by LED Widgets.

Learn more about Keys(按键).


LED 部件不处理任何 按键

了解有关 Keys(按键) 的更多内容。

Example

LED with custom style

#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_screen_active());
    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_screen_active());
    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_screen_active());
    lv_obj_align(led3, LV_ALIGN_CENTER, 80, 0);
    lv_led_on(led3);
}

#endif

API

lv_types.h

lv_led.h