Fastled blend - ws2812

Hi there -Have created a basic led lamp using strings of ws2812 and the fastled libray.

What I would like to do this change the colours over an hour period.

Reading up on think the best way to go about this is the blend command. I understand that blend is CRGB currentColor = blend(colorStart, colorTarget, blendAmount);.

Just can’t work out how to do work blendAmount over an hour period.

Thank you very much for reading this.

How are you planning to know that time is passing?

How accurate does an hour have to be?

What starts the process?

Getting the blendAmount variable when knowing the time between 0 and 60 minutes is a simple expression you may have forgotten about, just algebra.

If time is minutes, blendAmount, a number that is 0 .. 255 as it blends from one color to the other, can be calculated several ways

// Easy to understand:
blendAmount = map(minutes, 0, 59, 0, 255);

// Same thing, no map():
blendAmount = (minutes * 255) / 60;

a7

Do you own --
Arduino UNO and
Led strip?

Your ideas about millisCounter and the millis() function will help you answer @alto777’s question in post #1: “How are you planning to know that time is passing?”

Thanks was planning to use the command every_n_seconds, to advade colour, use an rtc to get start time from. Look at a colour array. Hope that makes sense.

You are not answering to the following questions?

You can avoid RTC if you use millisCounter and millis() function.

How many LEDs do you have in the string?

I believe you need to use millis(). Define a constant like

const unsigned long TRANSITION_TIME = 3600000UL; // 1 hour in ms

Does it mean that the ransition time from fully RED to fully Green will be over 1 hour? How long a particular blend will last -- 1 or 2 ms? Is the blending be on two colors (RG/GR or RB/BR or GB/BG) or on three colors (RGB)?

Thanks - Its easy to overthink things and get lost.

So if ;

present_colour = (250,50,50) or present_red, present_green, present_blue

target_colour = (50,250,50) or trarget_red, target_green, target_blue

colour_change = (250+50+50) - (50+250+50)

blendAmount = map(minutes, 0, 59, 0, colour_change )

every_n_seconds //change colour etc.

Is that right

Use proportions... If one color (r or g or b) has 50 steps to change to the next color, and another color (r or g or b) has 200 steps, then the first color will take 50/200 (1/4) step and the second color will take 1 step.

I made this synchronized color changer for a dancer wearing a WS2812 dress. It is a little hard to understand, but it has utility functions that try to show how it is working. If fades from one color to the next, proportionally (not HSV, just RGB).

Or, see "crossfade" function in this sketch... might be easier to understand...

My map2colour library could be useful way to mapping the seconds of the day to a color.
Depending on the array of colors you define, conversions are smooth, stable or “jumping”.

One defines 2 arrays, the first array holds values and the second holds the matching colors. These are the reference points and between those there is interpolation.
You might define one color for every hour, however the points do not need to be equidistant, so you can define e.g. (22:00 - 06:00) as a single color. The number of points is given in the constructor.

Your program could change the color array every weekday or weekend or depending on the temperature outside or whatever sensor. Postprocessing of the color generated is of course possible e.g. change brightness.

Thanks for that - sounds just what I am after. Looking quickly at the termperature example. it meet halfway between arrays….?

How would this fit with the fastled libray….?

Sorry if this are silly questions if have a good look and hack this evening !!

It's a bit more than you can expect from the actual code.

The blendAmount is a weight expressed as an integer between 0 and 255. A scalar variable.

The method you had in the first post

CRGB currentColor = blend(colorStart, colorTarget, blendAmount);

has the source and destination colors, and uses blenbAmount to add some of one color to some of the other. At 0, it's all colorStart, at 255 it's all colorTarget. In between are, um, in between colors.

When you know the time in minutes, you can calculate the blendAmount. Just a number.

present_colour = (250,50,50) or present_red, present_green, present_blue

target_colour = (50,250,50) or trarget_red, target_green, target_blue

//NO: colour_change = (250+50+50) - (50+250+50)

blendAmount = map(minutes, 0, 59, 0, colour_change )

CRGB currentColor = blend(present_color, target_color, blendAmount);

present_colour is misleading as a variabke name here, starting_colour woukd be more meaningful.

The present color in a timed wipe is, in this example, named currentColor.

a7

Thanks - so *
//NO: colour_change = (250+50+50) - (50+250+50)*

is wrong….?

I'm sure it means something to you, and I can imagine what.

It is not, however, anything like C code.

map() isn't magic, it operates on integers and will only do the kind of thing I did with it, take a range of one set (time in minutes up to 60) and a range of an output (0 .. 255) to get that number that is how far along the color change you want to be at that time.

a7

Thanks - Thought it was needed to work out the difference between the colours - so it was a small change ( eg 250, 240, 230 to 240,230,220) the range would not as smaller than ( 250,240,230, to 10,5,5), hope that makes sense to you as it make some sense to me !….?

The blend() function doesn't care what the two colours you specify are, how close or far apart visually or how possibly ugly it might be.

CRGB currentColor = blend(colorStart, colorTarget, blendAmount);

Just your end points, which are CRGB colours, and where you are 0 .. 255 going from the first to the second.

It has no idea where you are coming up with the blend amount argument. The time changing nature of blendAmount is used to determine the color the strip should be now.

a7

In a two-color FastLED blending experiment (from fully Red to fully Green), suppose the current blendAmount is 35 and the blendDuration is 60 seconds. My questions are:

1. What percentage of Green and what percentage of Red are mixed together at this blend value?

2. How long will this particular blended color be displayed before going with the next blendAmount?

All three color values decrement 10, so in each step, each color wil be decremented the same amount. A 1:1:1 proportion.

Underspecified! At what rate and step size are the changes being made?

a7

It seems the idea is to blend the colors through the day. I suspect a "dawn to dusk" simulation.