LED crossfade White to Orange

Hi!
I’m working on coding a RGB led to fade from 1 set color to another. This has proven to be a lot more difficult than i expected it to be… The goal is to fade the white colour into the more orange one, but so far i haven’t managed it yet. So far the fade worked but from yellow to white, guess this code desaturises the color. is there a way to do it the other way around?

This is the code I’m working with:

int redPin = 9;
int greenPin = 10;
int bluePin = 11;
uint8_t i = 0;
uint8_t f = 0;

void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
}

void loop() {
analogWrite(redPin, 250); // This is the white colour
analogWrite(greenPin, 250 );
analogWrite(bluePin, 255 );
i = i +2;
f++;
Serial.println(f);
Serial.println(i);
delay(10);
}

Hi,

To add code please click this link;

What RGB combination gives you the Orange that you want?

You might be better starting with code that has three pots, each controlling the intensity of each colour.
Printing to the serial monitor to see what your combination needs to be.

Thanks… Tom… :grinning: :+1: :coffee: :australia:

1 Like

Hi!
Oh that what you mentioned could also be an idea!

I started with that way at the beginning. I got the code i posted in the original post from someone on discord that was willing to help and explain. But initially i showed him this:
It’s a very simple code that circles back and forth between the 2 colors i wanted to achieve.
The cool at the beginning and the orange at the end

int redPin= 11;
int greenPin = 10;
int bluePin = 9;

void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

void loop() {
setColor(250, 250, 255); // Cool
delay(2000);
setColor(255, 80, 10); // Warm
delay(2000);

}

void setColor(int redValue, int greenValue, int blueValue) {
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
}

I guess what i’m doing now is a bit more of a tedious method to what you mentioned haha!
This is what i’m working on now. Looking at the serialmonitor and looking at what color it has, if it has to be less pink and more yellow and changing it. (not done yet)

int redPin= 9;
int greenPin = 10;
int bluePin = 11;

void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
}

void loop() {
setColor(250, 250, 255); Serial.println(1); // 1
delay(2000);
setColor(250, 250, 250); Serial.println(2);// 2
delay(2000);
setColor(250, 245, 240); Serial.println(3);// 3
delay(2000);
setColor(250, 240, 220); Serial.println(4);// 4
delay(2000);
setColor(250, 235, 210); Serial.println(5);// 5
delay(2000);
setColor(250, 230, 180); Serial.println(6);// 6
delay(2000);
setColor(250, 220, 170); Serial.println(7);// 7
delay(2000);
setColor(250, 210, 150); Serial.println(8);// 8
delay(2000);
setColor(250, 190, 140); Serial.println(9);// 9
delay(2000);
setColor(250, 170, 130); Serial.println(10);// 10
delay(2000);
setColor(250, 150, 130); Serial.println(11);// 11
delay(2000);
setColor(250, 140, 130); Serial.println(12);// 12
delay(2000);
setColor(250, 130, 120); Serial.println(13);// 13
delay(2000);
setColor(250, 120, 100); Serial.println(14);// 14
delay(2000);
setColor(250, 110, 80); Serial.println(15);// 15
delay(2000);
setColor(250, 100, 50); Serial.println(16);// 16
delay(2000);
setColor(250, 90, 40); Serial.println(17);// 17
delay(2000);
setColor(250, 80, 20); Serial.println(18);// 18
delay(2000);
setColor(255, 80, 10); Serial.println(19);// 19
delay(2000);

}

Hi,
Its a long way to do it, but if you have the time and understand your code, go for it.

Tom… :grinning: :+1: :coffee: :australia:

1 Like

Guess I have to start somewhere… Coders would probably cringe at the way i do it haha! Do you know a way to somehow fade the colors into each other a little more fluid? Now it’s a hard stop, but since the colors are close it is almost not noticeable

Hi,
I haven’t played with colour changes and mixes, but you post is young, so some other forum members may appear over the next few hours.

Tom… :grinning: :+1: :coffee: :australia: