Arrays, fading

I have a few rgb leds i would like to fade up and down simultaneously. I currently have one light fading up then down then moving on to the next light using arrays and a counter. What would the logic be for fading up the next light as the previous one is fading down?

Something like this

const int n_leds = 3;
const int fade_millis = 20;

int leds[n_leds];
int current_led;

void setup()
{
 current_led = 0;
 leds[0] = 255;
 leds[1] = 0;
 leds[2] = 0;
}

void loop()
{
 leds[current_led] -= 1;
 leds[(current_led+1)%n_leds] += 1;
 if(leds[current_led] == 0)
 current_led = (current_led+1) %n_leds;

 delay(fade_millis);
}

I'd like to direct your attention to the neopixels strandtest.ino

More or less right up your alley.

Don't use delay(). At each loop, read milis(), decide how bright each LED should be at the current time, and tell the LED to be that bright.

There's nothing wrong with banging digital pins using delay, provided there no need for concurrency. If there's no need for concurrency, there no need for the extra complexity.

Untested code below

const int n_leds = 3;

class LED
{
public:
 LED() { pin = -1; }
 LED(int p, int i) : pin(p), intensity(i) { }
 void on() { digitalWrite(pin, HIGH); }
 void off() { digitalWrite(pin, LOW); }

 int intensity;

private:
 int pin;
};

LED leds[n_leds];
int current_led;



void setup()
{
 current_led = 0;
 leds[0] = LED(1, 255);
 leds[1] = LED(2, 0);
 leds[2] = LED(3, 0);
}

void loop()
{
 int next_led = (current_led+1)%n_leds;
 leds[current_led].intensity -= 1;
 leds[next_led].intensity += 1;

 int d1, d2;
 d1 = leds[current_led].intensity/8;
 d2 = leds[next_led].intensity/8;
 if(d1 > d2)
 {
 int tmp = d1;
 d1 = d2;
 d2 = tmp;
 }

 leds[current_led].on();
 leds[next_led].on();

 delay(d1);
 leds[current_led].off();
 delay(d2-d1);
 leds[next_led].off();
 delay(32-d2);

 if(leds[current_led].intensity == 0)
 current_led = next_led;
}