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();
}