Here's my code. All I want it to do is fade to a specified color from whatever color it currently is.
I can't seem to figure out why, but it either keeps getting stuck at the same color, or it will always fade to white. Please assume everything else is correct and please help.
void fade2Color(int r, int g, int b){
int currR = leds[0].r;
int currG = leds[0].g;
int currB = leds[0].b;
while((currR != r) && (currG != g) && (currB != b)){
if(currR < r){
currR++;
}
else if(currR > r){
currR--;
}
if(currG < g){
currG++;
}
else if(currG > g){
currG--;
}
if(currB < b){
currB++;
}
else if(currB > b){
currB--;
}
fill_solid(leds, NUM_LEDS, CRGB(currR,currG,currB));
FastLED.show();
}
}
If needed the whole code is below:
#include <FastLED.h>
#define DATA_PIN 6
#define NUM_LEDS 500
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
void setup(){
Serial.begin(9600);
FastLED.addLeds<WS2812B, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
}
void loop(){
fill_solid(leds, NUM_LEDS, CRGB::Blue);
FastLED.show();
delay(5000);
fade2Color(212,111,0);
}
void fade2Color(int r, int g, int b){
int currR = leds[0].r;
int currG = leds[0].g;
int currB = leds[0].b;
while((currR != r) && (currG != g) && (currB != b)){
if(currR < r){
currR++;
}
else if(currR > r){
currR--;
}
if(currG < g){
currG++;
}
else if(currG > g){
currG--;
}
if(currB < b){
currB++;
}
else if(currB > b){
currB--;
}
fill_solid(leds, NUM_LEDS, CRGB(currR,currG,currB));
FastLED.show();
}
}