LED (lv_led)

Overview

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

Parts and Styles

The LEDs have only one main part, called LV_LED_PART_MAIN and it uses all the typical background style properties.

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.

Brightness

You can set their brightness with lv_led_set_bright(led, bright). The brightness should be between 0 (darkest) and 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.

Events

  • LV_EVENT_DRAW_PART_BEGIN and LV_EVENT_DRAW_PART_END is sent for the following types:

    • LV_LED_DRAW_PART_RECTANGLE The main rectangle. LV_OBJ_DRAW_PART_RECTANGLE is not sent by the base object.

      • part: LV_PART_MAIN

      • rect_dsc

      • draw_area: the area of the rectangle

See the events of the Base object too.

Learn more about Events.

Keys

No Keys are processed by the object type.

Learn more about Keys.

Example

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

MicroPython code  

 GitHub Simulator
#
# 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

enum lv_led_draw_part_type_t

type field in lv_obj_draw_part_dsc_t if class_p = lv_led_class Used in LV_EVENT_DRAW_PART_BEGIN and LV_EVENT_DRAW_PART_END

Values:

enumerator LV_LED_DRAW_PART_RECTANGLE

The main rectangle

Functions

lv_obj_t *lv_led_create(lv_obj_t *parent)

Create a led objects

参数

par -- pointer to an object, it will be the parent of the new led

返回

pointer to the created led

void lv_led_set_color(lv_obj_t *led, lv_color_t color)

Set the color of the LED

参数
  • led -- pointer to a LED object

  • color -- the color of the the LED

void lv_led_set_brightness(lv_obj_t *led, uint8_t bright)

Set the brightness of a LED object

参数
  • led -- pointer to a LED object

  • bright -- LV_LED_BRIGHT_MIN (max. dark) ... LV_LED_BRIGHT_MAX (max. light)

void lv_led_on(lv_obj_t *led)

Light on a LED

参数

led -- pointer to a LED object

void lv_led_off(lv_obj_t *led)

Light off a LED

参数

led -- pointer to a LED object

void lv_led_toggle(lv_obj_t *led)

Toggle the state of a LED

参数

led -- pointer to a LED object

uint8_t lv_led_get_brightness(const lv_obj_t *obj)

Get the brightness of a LEd object

参数

led -- pointer to LED object

返回

bright 0 (max. dark) ... 255 (max. light)

Variables

const lv_obj_class_t lv_led_class
struct lv_led_t

Public Members

lv_obj_t obj
lv_color_t color
uint8_t bright

Current brightness of the LED (0..255)