14 uint32_t fade_duration_ms,
15 const CRGB& target_color) {
17 auto state = std::make_shared<std::pair<CRGB, unsigned long>>(
22 [target_color, fade_duration_ms, state](uint32_t elapsed_ms,
CRGB& crgb) {
23 CRGB& from_color = state->first;
24 unsigned long& last_elapsed_ms = state->second;
26 if (elapsed_ms < last_elapsed_ms) {
29 last_elapsed_ms = elapsed_ms;
30 if (fade_duration_ms == 0 || elapsed_ms >= fade_duration_ms) {
35 blend(from_color, target_color, elapsed_ms * 255 / fade_duration_ms);
43 duration_ms, [duration_ms, reverse](uint32_t elapsed_ms,
CRGB& crgb) {
45 if (duration_ms == 0) {
46 crgb =
CRGB(255, 255, 255) - crgb;
50 crgb =
blend(
CRGB(255, 255, 255) - crgb, crgb,
51 elapsed_ms * 255 / duration_ms);
53 crgb =
blend(crgb,
CRGB(255, 255, 255) - crgb,
54 elapsed_ms * 255 / duration_ms);
62 uint32_t elapsed_ms,
CRGB& crgb) {
63 if (duration_ms == 0) {
64 crgb = reverse ? crgb : target_color;
68 crgb =
blend(target_color, crgb, elapsed_ms * 255 / duration_ms);
70 crgb =
blend(crgb, target_color, elapsed_ms * 255 / duration_ms);
CRGB blend(const CRGB &p1, const CRGB &p2, uint8_t amountOfP2)
Linear interpolation (blend) between two colors.