I’m new to the group…Is there a way to transform lets say from Red to Green smoothly?
Using the CHSV colors you can change an led from Hue Red (0) to Green (96) with a simple loop adding 1 to the Hue each loop.
leds[0] = CHSV(Hue,255,255);
FastLED.show();
Color Hue
Red 0
Red/Orange 16
Orange 32
Orange/Yellow 48
Yellow 64
Yellow/Green 80
Green 96
You can also interpolate between RGB colors directly if you don’t want to go through the HSV colors between the colors you want to fade. Something like:
CRGB interpolate(CRGB from, CRGB to, byte alpha) {
CRGB ret;
ret.r = map(alpha, 0, 255, from.r, to.r);
ret.g = map(alpha, 0, 255, from.g, to.g);
ret.b = map(alpha, 0, 255, from.b, to.b);
return ret;
}
Note: I’m sure there is a better way to do this with lib8tion
How about using HTML code colors:
for(int i = 0; i < NUM_LEDS; i++){
leds[i] = CRGB::Green;
}
edit
I just saw that you wanted it to be a “smooth” transition of colors. Adjust the delay to your liking. You will need it to control the frame rate of your fade, however the longer the delay the more “blocky” it will look.
Try this:
struct CRGB leds[LED_COUNT];
CRGB thiscolor = CRGB(0, 0, 0);
void loop(){
for(int i = 0 ; i< 255; i++ ) { //—FADE BLACK TO RED
thiscolor = thiscolor + CRGB(1, 0, 0);
fill_solid( leds, LED_COUNT, thiscolor);
FastLEDS.show();
delay(25);
}
for(int i = 0 ; i< 255; i++ ) { //—FADE RED TO BLACK
thiscolor = thiscolor - CRGB(1, 0, 0);
fill_solid( leds, LED_COUNT, thiscolor);
FastLEDS.show();
delay(25);
}
}
/* if you are trying to fade from a full RED color directly without fading back to black, you will see more colors than you want.
try this code to experiment with this effect
*/
for(int i = 0 ; i< 255; i++ ) { //—FADE BLACK TO RED
thiscolor = thiscolor + CRGB(1, 0, 0);
fill_solid( leds, LED_COUNT, thiscolor);
FastLEDS.show();
delay(25);
}
for(int i = 0 ; i < 255; i++ ) { //—FADE RED TO GREEN
thiscolor = thiscolor - CRGB(1, 0, 0); //subtract red
thiscolor = thiscolor + CRGB(0, 1, 0); //add green
fill_solid( leds, LED_COUNT, thiscolor);
FastLEDS.show();
delay(50);
}
}
@Shlomo_Zippel
I’m new to all this what is alpha,from and to need to set to?
@Greg_Heinz from would be the color you’re transitioning from, to would be the color you’re transitioning to, and alpha would be your position in the transition (0 being the from color, 255 being the to color, and 128 being right in the middle between the two. A 10 second transition from red to green would be:
void loop() {
byte alpha = millis() / 10000.0 * 255; // you should clamp to 255
FastLEDS.showColor(interpolate(CRGB::red, CRGB green, alpha));
}
I would recommend not using “alpha” as a term here - as that has a specific meaning (referring to transparency in layers), and while the library doesn’t have any official support yet, alpha channel support is something we will be adding soon 
Good point, I’ll be more careful about terminology and loaded terms
@Shlomo_Zippel Sorry for being such a noob but here is my code: but I’m getting errors
Can you point me in the right direction.
#include <FastSPI_LED2.h>
// Pin to which the input of the matrix is connected
#define String1_DATA_PIN 6
//—LED SETUP STUFF
const int ledsPerStrip = 60;
//—LED FX VARS
int max_bright = 128; //-SET MAX BRIGHTNESS TO 1/4
CRGB String1_leds[60];
//------------------SETUP------------------
void setup()
{
LEDS.addLeds<WS2811, String1_DATA_PIN ,GRB>(String1_leds, ledsPerStrip);
LEDS.setBrightness(max_bright); // SET BRIGHTNESS TO 1/4 POWER
fill_solid(&(String1_leds[0]), (ledsPerStrip), 0x0); //-CLEAR STRIP
LEDS.show();
delay(2000);
}
//-----------------Loop-----------------
void loop() {
byte temp = millis() / 10000.0 * 255; // you should clamp to 255
LEDS.showColor(interpolate(CRGB::red, CRGB green, temp));
LEDS.show();
delay(2000);
Errors:
C:\Users\greg\Documents\Arduino\libraries\FastSPI_LED2_RC5/pixeltypes.h: In function ‘void loop()’:
C:\Users\greg\Documents\Arduino\libraries\FastSPI_LED2_RC5/pixeltypes.h:75: error: invalid use of non-static data member ‘CRGB::::::::red’
sketch_jan21a:26: error: from this location
sketch_jan21a:26: error: expected primary-expression before ‘green’
sketch_jan21a:26: error: ‘String1_leds’ cannot be used as a function
first off, your fill solid line can just be fill_solid(String1_leds, ledsPerStrip, 0x0); Though LEDS.clear(); will do the same thing.
Secondly, make your showColor line:
LEDS.showColor(interpolate(CRGB::Red, CRGB::Green, temp));
The capital R in Red and G in Green are important.
Also - you were missing the :: between CRGB and Green for CRGB::Green.
Finally, showColor - as the name implies - shows the color, making the call to LEDS.show() below it redundant.
Also no need for the delay(). The transition will happen over 10 seconds regardless of your framerate
I’m still getting this error
sketch_jan21a.ino: In function ‘void loop()’:
sketch_jan21a:29: error: ‘interpolate’ was not declared in this scope
Do I still have some kind of typo?
Have you defined the function interpolate? Shlomo gave an example implementation above.
Thanks Daniel… I missed that.
Shlomo or Daniel,
Can you explain how this works to me
Thanks!
I’ll post a working code snippet when I get home!
Shlomo and Daniel Thanks so much I got it all working now!
Greg