FadLed timing

I am using the FadeLed library to fade three LEDS and I want each led to fade up and down in sequence

I tried using millis() timing shown in my attached sketch but I cannot get the timing to work out exactly and as time progresses the leds start to overlap each other.

Is there a way to trigger the next led in sequence using leds.done or some other trigger.

Thanks
Bill

LIGHTHOUSE_9_TEST.ino (4.61 KB)

I am using the FadeLed library

That you got as a blue light special at KMart?

I don't understand your reply but the FadeLeds library is in the ARDUINO PLAYGROUND at "Arduino Playground - FadeLed "

There is a typo in my original post leds .done should be leds.done.

I would really appreciate some help.

Thanks
Bill

http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html

The program you posted is a bit cluttered with stuff. But if you want to fade 3 leds in sync you can use the .done() and .getCurrent() methods pretty easy.

But “fade up and down in sequence” is still a bit vague. Do you want to first fade up and down the red led and start the Green when the red turned off etc? And fade red up again once the white turned off again?

I think this should do that:

#include <FadeLed.h>

FadeLed leds[] = {9, 10, 11};
const byte NrLeds = sizeof(leds)/sizeof(leds[0]);

byte currentLed = 0;

void setup() {
  //for now I set them all to fade in 2 seconds (constant speed mode)
  for(byte i = 0; i < NrLeds; i++){
    leds[i].setTime(2000);
  }
  
  //and I start fading the first
  leds[currentLed].on();
}

void loop() {
  FadeLed::update();
  
  //if done fading up
  if(leds[currentLed].done() && leds[currentLed].get()){
    //fade down again
    leds[currentLed].off();
  }
  //if done fading down
  else if(leds[currentLed].done() && !leds[currentLed].get()){
    //go to next led
    currentLed++;
    if(currentLed >= NrLeds){
      currentLed = 0;
    }
    
    //and start fading that
    leds[currentLed].on();
  }
}

Untested though :stuck_out_tongue:

SEPTILLION;

Thank you, it works perfectly.
My code was really cluttered before I cleaned it up and posted it; I was going around in circles and getting deeper in confusion the more I tried.
Thank you again.

Bill

I know the feeling. Sometimes it's just easier to trow everything in the bin and start fresh. That way you really know what you want instead of bolting code to a so-and-so-base :slight_smile:

Good it works!