Hi there, thought I’d share my (what I consider to be) improved rainbow effect.
lambda: |-
uint8_t led_change = 24; //(higher is more change) the difference in hue for each led down the strip
float speed = 7; //(lower is faster) the speed the first led colour changes at (therefore affecting all)
if (initial_run) {
it.all() = Color(0, 0, 0);
}
unsigned long time = millis() / speed;
int repetitions = time / 1529;
uint16_t hue = time - (1529 * repetitions);
for (int i = 0; i < it.size(); i++) {
if (hue >= 0 && hue < 255) {
uint8_t green = hue;
it[i] = Color(255, green, 0);
} else if (hue >= 255 && hue < 510) {
uint8_t red = hue - 255;
it[i] = Color((255 - red), 255, 0);
} else if (hue >= 510 && hue < 765) {
uint8_t blue = hue - 510;
it[i] = Color(0, 255, blue);
} else if (hue >= 765 && hue < 1020) {
uint8_t green = hue - 765;
it[i] = Color(0, (255 - green), 255);
} else if (hue >= 1020 && hue < 1275) {
uint8_t red = hue - 1020;
it[i] = Color(red, 0, 255);
} else if (hue >= 1275 && hue < 1530) {
uint8_t blue = hue - 1275;
it[i] = Color(255, 0, (255 - blue));
}
hue+=led_change;
if (hue >= 1530) {
hue-=1530;
}
}
The default rainbow effect I found to be too dull in the mixed led colours and only bright on the single led colours. This effect focuses on making sure all colours are equally shown (imo).
I’m also currently working on an effect that uses the currently chosen colour in Home Assistant and (not sure if this is the right term) waves colours similar to it.
lambda: |-
uint8_t led_change = 15; //(higher is more change) the difference in hue for each led down the strip
uint8_t hue_variation = 180; //(higher is more variation) the amount the hue changes from the current colour
int speed = 7; //(lower is faster) the speed the first led colour changes at (therefore affecting all)
if (initial_run) {
it.all() = Color(0, 0, 0);
}
Color pickedColor = current_color;
uint16_t pickedHue = 1500;
if (pickedColor.b == 0) {
if (pickedColor.g < 255) {
pickedHue = 1000 + pickedColor.g;
} else {
pickedHue = 1255 + (255 - pickedColor.r);
}
} else if (pickedColor.r == 0) {
if (pickedColor.b < 255) {
pickedHue = 1510 + pickedColor.b;
} else {
pickedHue = 1765 + (255 - pickedColor.g);
}
} else if (pickedColor.g == 0) {
if (pickedColor.r < 255) {
pickedHue = 2020 + pickedColor.r;
} else {
pickedHue = 2275 + (255 - pickedColor.b);
}
}
uint16_t minHue = pickedHue - hue_variation;
uint16_t maxHue = pickedHue + hue_variation;
unsigned long time = millis() / speed;
int repetitions = time / (hue_variation * 2);
uint16_t hue = minHue + (time - ((hue_variation * 2) * repetitions));
bool backwards = false;
if ((repetitions % 2) == 0) {
backwards = true;
} else {
backwards = false;
}
if (backwards) {
hue = minHue + (maxHue- hue);
}
for (int i = 0; i < it.size(); i++) {
if (hue >= 1000 && hue < 1255) {
uint8_t green = hue - 1000;
it[i] = Color(255, green, 0);
} else if (hue >= 1255 && hue < 1510) {
uint8_t red = hue - 1255;
it[i] = Color((255 - red), 255, 0);
} else if (hue >= 1510 && hue < 1765) {
uint8_t blue = hue - 1510;
it[i] = Color(0, 255, blue);
} else if (hue >= 1765 && hue < 2020) {
uint8_t green = hue - 1765;
it[i] = Color(0, (255 - green), 255);
} else if (hue >= 2020 && hue < 2275) {
uint8_t red = hue - 2020;
it[i] = Color(red, 0, 255);
} else if (hue >= 2275 && hue < 2530) {
uint8_t blue = hue - 2275;
it[i] = Color(255, 0, (255 - blue));
} else if (hue >= 745 && hue < 1000) {
uint8_t blue = hue - 745;
it[i] = Color(255, 0, (255 - blue));
} else if (hue >= 2530 && hue < 2785) {
uint8_t green = hue - 2530;
it[i] = Color(255, green, 0);
} else {
it[i] = Color(255, 255, 255);
}
hue+=led_change;
if (hue >= maxHue) {
hue-=(hue_variation * 2);
}
}
Currently the colours seems to only fade correctly on the first led and I can’t figure out how to properly do it for the rest of the strip
With both effects, changing the variable with the comments will change certain aspects about the effect.
Side note: I’m not sure if this is a well known thing or not, but I still wish I had known it sooner; The addressable lambda section for FastLED lights is extremely similar to how you would write code for a FastLED light on an Arduino using the Arduino IDE. Means that most FastLED functions (like beatsin16()
for example) can be used within the lambda.