I have added "MINIMUM_BRIGHTNESS" to prevent the produced colors from being too dark. Here "colCur" is the current CRGB value of the transition It is not complicated, some ppl are over-complicating it in order to show off! My example with arrays of 3 bytes (red, green and blue components) are more or less interchangeable with the CRGB structure: #define TRANSITION_MILLIS 5000ĬolCur.raw = map(transitionPos, 0, TRANSITION_LENGTH-1, colSrc.raw, colDst.raw) So when you want to move from one color to the other one, say from Hue = 10 to Hue = 67 then you just need to do the same simple math formula I had above for that hue element If you always want your led at constant brightness and saturation, then you don't even need to have those values in the array and you can store in your array only the hue of the LED you want (the "hue" is kinda the color). So instead of declaring your first array with RBG colors, use HSV colors with the function CHSV( Hue, Saturation, Value aka brighness) That being said, just noticed you are actually using the FastLED library. So we start at the initial color, ends at the target one and in between you move between the 2ĭoes it make it easier to understand what we mean ? that's what the formula above was doingĪt i = 0, the second part of the equation disappear (multiplied by 0) and you can see thatįadeR N = R 0 + N * (R 1 - R 0) / N = R 0 + (R 1 - R 0) = R 1 So you start from the initial value and add (or subtract) a bit at each stage. The easy way to do this in N steps is to look at how much you need to change the value at each steps. So you basically need a math formula that takes your parameters of CRGB() Imagine you want to move from the second one, orange CRGB(255, 80, 0) to the last one white CRGB(255, 255, 255)Īn "easy" (but as I said not the best looking path) way to perform the transition is to create a number of steps that will transform each individual components of your RGB initial value orange CRGB(255, 80, 0) into the one for the white target CRGB(255, 255, 255) your colors are RGB as you create them with CRGB Colours = Sounds a bit too complicated for me at this stage The code is untested but it should work with minor modifications. Here "colCur" is the current RGB value of the transition Memcpy(colCur, colDst, sizeof(colDst)) //set current colorįor (idx = 0 idx < 3 idx++) colCur = map(transitionPos, 0, TRANSITION_LENGTH-1, colSrc, colDst) Memcpy(colSrc, colDst, sizeof(colDst)) //copy dst to src Unsigned long transitionStart, transitionPos This will create random colors with 5 second transitions: #define TRANSITION_MILLIS 5000īyte colSrc, colDst, colCur //R=0, G=1, B=2 No need to complicate things with all sorts of color models and what not. Green = 255 - fade // Fade from Cyan to BlueĬase 4: Red = fade // Fade from Blue to MagentaĬase 5: Red = 255 // Fade from Magenta to Red Int fade = (6 * hue) % 1024 // How far into the part we are (0-1023)Ĭase 1: Red = 255 - fade // Fade from Yellow to Green Int hextant = (hue * 6) / 1024 // Divide the range int 6 parts (0-5) Int hue = analogRead(potPin) // A hue value from 0 to 1023 For full saturation and brightness this sketch takes a Hue value from 0 (Red) to 1023 (Violet) and converts it to R, G, and B components: const byte potPin = A2 When fading between colors it is often better to use a color model where Hue (the color) is separated from brightness and saturation. I = random(sizeof(Colours)/sizeof(Colours)) Int i = random(sizeof(Colours)/sizeof(Colours)) The only thing I would like to add now is more of a fade between the random colors instead of simplyĪny ideas how I could achieve this ? (I'll obviously need to work on the timing once I get the fades I'm using 3 single addressable LEDS to achieve this and am trying to simulate a lava / fire effect. With the awesome assistance of the forum have written the following code for lighting effects on a puppet.
0 Comments
Leave a Reply. |