I want to change RGB values according to the percentage. means 0% should show Red , 50% should green and 100% will Blue color.I am working on fastled.I tried like this but didnt get the best result.can anyone suggest some good stuf??
int R,G,B;
int p = percentage;
if(p >= 0 and p <= 50){
R = abs(p - 100);
G = p*2;
}
if(p > 50 and p <= 100){
G = abs(p - 100);
B = p*2;
}
>! also tried
R = abs(p-100);
G = p/2;
B = p;
leds[0] = CRGB(R,G,B);
FastLED.show();
From your problem statement, you probably want something like this which generates RGB colors counter-clockwise around the sRGB color gamut from red to blue.
Output:
This creates a (reversed) rainbow type from red to blue for 0% to 100%. Additionally, this has been expanded to allow percentages to exceed 100 which can be used to produces colors going from blue->violet->purple and back to red. Here's an image created from this going from percent 0 to 100: