@INTEL, l Here’s an except out of a YAML file for a project I did with esphome where I defined a number of additional FastLED effects. I had a string of 100 WS2812 LEDs arranged as a stack of rings that looks like this:
Some of the effects are defined like this:
light:
- platform: fastled_clockless
chipset: WS2811
pin: GPIO13
num_leds: 100
rgb_order: RGB
name: "Tower"
id: tower
effects:
- flicker:
- fastled_rainbow:
- fastled_color_wipe:
- fastled_scan:
- fastled_twinkle:
- fastled_random_twinkle:
- fastled_fireworks:
- fastled_flicker:
- fastled_lambda:
name: rings
update_interval: 100ms
lambda: |-
static uint8_t current_ring = 0;
static uint8_t current_hue = 0;
auto leds = it.leds();
fadeToBlackBy(leds, it.size(), 100);
current_ring = (current_ring + 1) % led_rings;
for (int i = 0; i < led_ringsize; i++)
leds[ledoffset(current_ring, i)] = CHSV(current_hue, 255, 200);
if (current_ring >= led_rings - 1)
leds[0] = CHSV(current_hue, 255, 255);
if (current_ring == 0) {
current_hue += 10;
if (current_hue > 255)
current_hue = 0;
}
it.schedule_show();
- fastled_lambda:
name: "Red Alert"
update_interval: 100ms
lambda: |-
static uint8_t current_ring = 0;
fadeToBlackBy(it.leds(), it.size(), 100);
current_ring = (current_ring + 1) % led_rings;
for (int i = 0; i < led_ringsize; i++)
it.leds()[ledoffset(current_ring, i)] = CHSV(0, 255, (128 * current_ring)/(led_rings - 1) + 127);
if (current_ring >= led_rings - 1)
it.leds()[0] = CRGB(255,255,0);
it.schedule_show();
- fastled_lambda:
name: bounce
update_interval: 100ms
lambda: |-
static int current_ring = 0;
static int direction = 1;
static uint8_t current_hue = 0;
auto leds = it.leds();
fadeToBlackBy(leds, it.size(), 100);
current_ring = (current_ring + direction);
if (current_ring < 0) {
current_ring = 0;
direction = 1;
}
if (current_ring >= led_rings) {
current_ring = led_rings - 1;
direction = -1;
}
for (int i = 0; i < led_ringsize; i++)
leds[ledoffset(current_ring, i)] = CHSV(current_hue, 255, 200);
if (current_ring >= led_rings - 1)
leds[0] = CHSV(current_hue, 255, 255);
if (current_ring == 0) {
current_hue += 10;
if (current_hue > 255)
current_hue = 0;
}
it.schedule_show();
- fastled_lambda:
name: clock
update_interval: 100ms
lambda: |-
// clock
auto time = id(sntp_time).now();
uint8_t seconds = time.second;
uint8_t minutes = time.minute;
uint8_t hours = time.hour;
uint8_t seconds_tens = seconds / 10;
uint8_t minutes_tens = minutes / 10;
uint8_t hours_tens = hours / 10;
seconds = seconds % 10;
minutes = minutes % 10;
hours = hours % 10;
static int ticks = 0;
static uint8_t col_start = 0;
#define col_hours_tens (col_start)
#define col_hours (col_start + 1)
#define col_minutes_tens (col_start + 2)
#define col_minutes (col_start + 3)
#define col_seconds_tens (col_start + 4)
#define col_seconds (col_start + 5)
const unsigned int hue_hours = HUE_GREEN;
const unsigned int hue_minutes = HUE_BLUE;
const unsigned int hue_seconds = HUE_RED;
// column 0 - tens of hours
// column 1 - hours
// column 2 - tens of minutes
// column 3 - minutes
// column 4 - tens of seconds
// column 5 - seconds
// flash top ring dim red/dim blue by seconds
//if (++ticks > 150) { // note update_interval above
// ticks = 0;
// if (--col_start < 0)
// col_start = led_ringsize;
//}
auto leds = it.leds();
fadeToBlackBy(leds, it.size(), 200);
CRGB flash = (seconds & 1) ? CRGB::Cyan : CRGB::Magenta;
leds[0] = flash;
// invert state for other
flash = ((seconds & 1) == 0) ? CRGB::Cyan : CRGB::Magenta;
leds[ledoffset(led_rings - 1, col_start + 8)] = flash;
// const unsigned int led_spacer = 1;
// const unsigned int led_rings = 9;
// const unsigned int led_ringsize = 11;
// int ledoffset(unsigned int ring, unsigned int member)
for (int i = 0; i < led_rings; i++) {
leds[ledoffset(i, col_hours_tens)] = CHSV(hue_hours, /*sat*/ 255, /*brightness*/ 00);
leds[ledoffset(i, col_hours)] = CHSV(hue_hours, /*sat*/ 150, /*brightness*/ 00);
leds[ledoffset(i, col_minutes_tens)] = CHSV(hue_minutes, /*sat*/ 255, /*brightness*/ 00);
leds[ledoffset(i, col_minutes)] = CHSV(hue_minutes, /*sat*/ 150, /*brightness*/ 00);
leds[ledoffset(i, col_seconds_tens)] = CHSV(hue_seconds, /*sat*/ 255, /*brightness*/ 00);
leds[ledoffset(i, col_seconds)] = CHSV(hue_seconds, /*sat*/ 150, /*brightness*/ 00);
}
for (int i = 1; i <= seconds_tens; i++)
leds[ledoffset(i - 1, col_seconds_tens)] = CHSV(hue_seconds, /*sat*/ 255, /*brightness*/ 250);
for (int i = 1; i <= seconds; i++)
leds[ledoffset(i - 1, col_seconds)] = CHSV(hue_seconds, /*sat*/ 150, /*brightness*/ 250);
for (int i = 1; i <= minutes_tens; i++)
leds[ledoffset(i - 1, col_minutes_tens)] = CHSV(hue_minutes, /*sat*/ 255, /*brightness*/ 250);
for (int i = 1; i <= minutes; i++)
leds[ledoffset(i - 1, col_minutes)] = CHSV(hue_minutes, /*sat*/ 150, /*brightness*/ 250);
for (int i = 1; i <= hours_tens; i++)
leds[ledoffset(i - 1, col_hours_tens)] = CHSV(hue_hours, /*sat*/ 255, /*brightness*/ 250);
for (int i = 1; i <= hours; i++)
leds[ledoffset(i - 1, col_hours)] = CHSV(hue_hours, /*sat*/ 150, /*brightness*/ 250);
it.schedule_show();
This might give you an idea of how to add more effects with your own C++ code. You can get into all sorts of creative trouble using lambda
in esphome…