Making a green-yellow-red gradient is most certainly possible, but I'd call that a new effect.
I had to look for an "easy" way to make a gradient and it seems the latest FastLED library has a DEFINE_GRADIENT_PALETTE function for that.
(untested by me, since I do not have my LED strips readily available)
So in the beginning of your code (before "void setup()") we need to define the palette we're going to use.
The numbers are set in this order:
// not real code! Just to illustrate what the numbers mean
DEFINE_GRADIENT_PALETTE(heatmap_gp) {
StartPosition1, RedPos1, GreenPos1, BluePos1,
StartPosition2, RedPos2, GreenPos2, BluePos2,
StartPosition3, RedPos3, GreenPos3, BluePos3 };
(you can define more colors if you'd like by simply adding a line - just make sure the starting point of each color is greater than the previous color in the gradient)
DEFINE_GRADIENT_PALETTE(heatmap_gp) {
0, 0, 0, 255, //green starts at led 0
128, 255, 255, 0, //yellow at led 128
224, 255, 0, 0, //red at led yellow };
CRGBPalette16 myPalette = heatmap_gp;
// after this the void setup function
With this we have created a gradient scale of 255 steps, called "myPalette".
Next we have to use this in a function, something like this:
void ShowPalette( int LEDCount ) {
// set all LEDs to black
FastLED.clear();
// Copy Gradient
for(int i; i<LEDCount; i++ ) {
leds[i] = ColorFromPalette( myPalette, (255/NUM_LEDS) * i );
}
// Show the gradient
FastLED.show();
}
You see the calculation ( (255/NUM_LEDS)*i ) which is needed to convert a 255 color count to match a NUM_LEDS number of LEDs (since you most likely do not have 255 LEDs on your guitar 🤣 ).
This means that the number of displayed LEDs will display the entire color range only when all LEDs (NUM_LEDS) are being lit.
Alternatively, you could scale the gradient so that the gradient always shows the 3 colors (so the gradient grows and shrinks with the LEDCount we pass to the function).
This could be done something like this:
void ShowPalette( int LEDCount ) {
// set all LEDs to black
FastLED.clear();
// Copy Gradient
for(int i; i<LEDCount; i++ ) {
leds[i] = ColorFromPalette( myPalette, (255/LEDCount) * i );
}
// Show the gradient
FastLED.show();
}
We can call this effect like so:
ShowPalette(random(0,NUM_LEDS)); // pick a random length between zero and NUM_LEDS-1
You'll have to play a little with the numbers to get it just right for your purposes. of course.
For example; when calling ShowPalette, I'd want to make sure that there is a minimum number of LEDs visible, for example
ShowPalette(random(15,NUM_LEDS)); // pick a random length between 15 and NUM_LEDS-1
Again: I have not tested this code, since my gear is not anywhere near me.