Update light lambda effect example (#125)

* Update index.rst

* Use modern API
This commit is contained in:
jdads1 2019-01-17 18:48:59 +00:00 committed by Otto Winter
parent cb2097ce6a
commit e30cc782f1
1 changed files with 8 additions and 4 deletions

View File

@ -278,15 +278,19 @@ This effect allows you to write completely custom light effects yourself using :
update_interval: 1s
lambda: |-
static int state = 0;
auto call = id(my_light).turn_on();
// Transtion of 1000ms = 1s
call.set_transition_length(1000);
if (state == 0) {
id(my_light).start_transition(light::LightColorValues::from_rgb(1.0, 1.0, 1.0)));
call.set_rgb(1.0, 1.0, 1.0);
} else if (state == 1) {
id(my_light).start_transition(light::LightColorValues::from_rgb(1.0, 0.0, 1.0)));
call.set_rgb(1.0, 0.0, 1.0);
} else if (state == 2) {
id(my_light).start_transition(light::LightColorValues::from_rgb(0.0, 0.0, 1.0)));
call.set_rgb(0.0, 0.0, 1.0);
} else {
id(my_light).start_transition(light::LightColorValues::from_rgb(0.0, 0.0, 0.0)));
call.set_rgb(1.0, 0.0, 0.0);
}
call.execute();
state += 1;
if (state == 4)
state = 0;