Light Control (LED)¶
1. Overview¶
The led in the component package is a light control component, which provides the following common scene light control codes.
-
Color lamp: RGB lamp or RGB W lamp, using PWM control and HSV color gamut space, with rich colors and good brightness effect, can adjust the color and brightness separately without affecting each other;
-
Nightlight: PWM control, adjustable brightness;
-
Blinking light: use ordinary IO and software timer control, one for reference in toys, and one simple IO to achieve wake-up response effect.
2. Instructions¶
| Function interface | Description |
|---|---|
| color_light_init | Initialize lamp control components |
| color_light_control | Set Color (HSV all) |
| color_light_set_level | Set Color (hue and saturation) |
| color_light_set_color | Set brightness (value(lightness)) |
| night_light_init | Light initialization |
| night_light_set_brightness | Setting brightness of light |
| blink_light_init | Blink initialization |
| blink_light_on | Blink light is turned on once |
Example:
#define POWER_ON_COLOR 360,1.0,1.0 //179,0.32,0.3
/*Color lamp example*/
void light_init(void)
{
/*Initialize lamp control components*/
color_light_init();
/*Set Color*/
color_light_control(POWER_ON_COLOR);
color_light_set_level(0.0);
ci_loginfo(LOG_USER,"color light ok\n");
for(int i=0;i<100;i++)
{
color_light_set_level((float)i/100.0);
vTaskDelay(pdMS_TO_TICKS(50));
}
}
/*Example of night light*/
void light_sample(void)
{
/*Initialize*/
night_light_init();
/*Turn on the light and set the brightness to 80%*/
night_light_set_brightness(1,80);
/*Turn off the light*/
night_light_set_brightness(0,80);
}
/*Example of flashing lights*/
void light_sample(void)
{
/*Initialize*/
blink_light_init();
/*Blink once*/
blink_light_on();
}