LED (lv_led)
Overview
LEDs are rectangle-like (or circle) Widgets whose brightness can be adjusted. With lower brightness the color of the LED becomes darker.
Parts and Styles
LV_LED_PART_MAIN
uses the typical background style properties.
Usage
Color
You set the color of the LED with lv_led_set_color(led, lv_color_hex(0xff0080)). This will be used as its background color, border color, and shadow color.
Brightness
You can set their brightness with lv_led_set_brightness(led, brightness).
The brightness
value should be in the range 0 (darkest) to 255 (lightest).
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].
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.
Keys
No Keys are processed by LED Widgets.
Further Reading
Learn more about Keys.
Example
LED with custom style
C code
View on 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_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