mirror of
https://github.com/esphome/esphome-docs.git
synced 2025-03-12 13:39:50 +01:00
Make initial run variable available to addressable_lambda (#558)
* Make initial run variable available to addressable_lambda * Update light docs
This commit is contained in:
parent
77ae4d9037
commit
1fce98177b
@ -714,8 +714,11 @@ Addressable Lambda Effect
|
||||
|
||||
This effect allows you to access each LED individually in a custom light effect.
|
||||
|
||||
You're passed in one variable: ``it`` - an :apiclass:`AddressableLight <light::AddressableLight>`
|
||||
instance (see API reference for more info).
|
||||
Available variables in the lambda:
|
||||
|
||||
- **it** - :apiclass:`AddressableLight <light::AddressableLight>` instance (see API reference for more info).
|
||||
- **current_color** - :apiclass:`ESPColor ` <light::ESPColor>` instance (see API reference for more info).
|
||||
- **initial_run** - A bool which is true on the first execution of the lambda. Useful to reset static variables when restarting a effect.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
@ -743,6 +746,33 @@ instance (see API reference for more info).
|
||||
it.range(0, 50) = ESPColor::BLACK;
|
||||
it.all().fade_to_black(10);
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
light:
|
||||
- platform: ...
|
||||
effects:
|
||||
- addressable_lambda:
|
||||
name: "My Custom Effect"
|
||||
update_interval: 16ms
|
||||
lambda: |-
|
||||
// Static variables keep their value even when
|
||||
// stopping and starting the effect again
|
||||
static uint16_t progress = 0;
|
||||
|
||||
// normal variables lost their value after each
|
||||
// execution - basically after each update_interval
|
||||
uint16_t changes = 0;
|
||||
|
||||
// To reset static when stopping and starting the effect
|
||||
// again you can use the initial_run variables
|
||||
if (initial_run) {
|
||||
progress = 0;
|
||||
it.all() = ESPColor::BLACK;
|
||||
// optionally do a return so nothing happens until the next update_interval
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Examples of this API can be found here:
|
||||
https://github.com/esphome/esphome/blob/dev/esphome/components/light/addressable_light_effect.h
|
||||
(the built-in addressable light effects).
|
||||
|
Loading…
Reference in New Issue
Block a user