![]() ![]() 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. "hue" would be the one you change with your pot - the others can be static values (or you could add more pots to control those too).With the awesome assistance of the forum have written the following code for lighting effects on a puppet. Given three 8 bit values (0-255) of "hue" "sat" and "val" it will calculate the red, green and blue values. ![]() I'm going to include one here that I use in my chipKIT TFT display library "Cariad". You can think of HSV as the "Human" colour space, and RGB as the "Digital" colour space.įortunately it's relatively simple to convert from one to another and there are a number of code snippets online that give examples of how to do it. However physical devices don't generally work with that colour space, so you need to be able to translate between them. HSV is a convenient way of visually manipulating colour since it gives you easy to understand "Hue" (the colour), "Saturation" (how much colour) and "Value" (or "Brightness" - how light the colour is) values that are easy for a human to understand. Your colour printer works in the CMYK colour space.ĭifferent colour spaces represent the colour using different values and combinations of values, and which colour space you use may be imposed by technical limitations (such as in the printer it is dictated by the combination of the colours of the inks). An RGB LED of course also displays in the RGB colour space. You computer monitor displays colour in the RGB colour space - red, green and blue. What you are controlling there is one out of three values from the HSV (aka HSB) colour space.Ĭolour can be represented in a number of different ways, called "spaces". ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |