fading different LEDs up and down in an if statement

Hi I am writing a program for an aquarium LED light that will simulate sunrise and sun set.

At the moment the program for sunrise looks like this

void sunRise()
{
   unsigned long now = millis();
   if(now - lastChange > SunRiseRamp) 
   {
      fadeUp ++; 
      fadeUp = constrain(fadeUp, 0, 255);
      analogWrite(rLEDpin, fadeUp);
      analogWrite(bLEDpin, 0);
      analogWrite(wLEDpin, 0);
      lastChange = now; 
   }
}

This simply fades up 1 led from zero to 255.

However, i found a website that suggests for a sunrise do the following:

fade red led from 0 to 100%. at red 50%, fade white in from 0 to 100%. When whites get to 50% (red will be at 100%) fade reds to zero while continuing to fade whites up to 100%. So at the end of the program whites are at 100% and reds are off.

Any suggestions on how to do this

Kr Craig

Make two parts: the timing and the sequence.

For the sequence, you might have to make a drawing for the colors. Assume a counter from 0...100 or 0...1024. Perhaps 0...1024 is better for a smoother change of brightness. Write a sketch that sets the leds according to the counter. It will be a lot of 'if'-statements.

Take a look at the map() and constrain() functions. A number of 'if'-statements, and a 'map()' and 'constrain()' for each led, and that's all.

Create a timing with millis() to generate the counter. Make it flexible to be able to make it slower or faster.

Combine both. You can do the sequence for the leds with every change of the counter, or let it run free and do the sequence whether the counter has changed or not. I prefer to let it run free, but when the analogWrite() is called too often, it might not work very well. So a certain delay has to be added. The PWM output is about 500Hz, so a change every 20ms should be fine.