Staggered starts for each instance in LedFlasher library?

Hi All

I've used Nick Gammon's LedFlasher library quite successfully for flashing various leds (many thanks for that Nick :)), but I'm at a loss now on how to stagger the start point for each led. In other words, I can get all the leds to start their sequences at the same time, but I can't work out how to, for instance, have three leds that flash at identical intervals, but overlap their flashing sequence because they start, say 200ms after each other. I'd like to work out a sequence for three leds that goes:

A=on, B=on, C=off then
A=off, B=on, C=on then
A=on, B=off, C=on ad infinitum

I've tried inserting a delay between each "ledname.begin" line in setup(), but that only works between two leds - not three for some reason.

Can anyone save me more fruitless hours of headscratching over this? Nick?

Thanks in advance guys.

Anyone?

I've tried inserting a delay between each "ledname.begin" line in setup(), but that only works between two leds - not three for some reason.

There is a sticky at the top of this forum that you are supposed to read BEFORE posting. Had you actually read that, you'd know that there are no mind readers here.

Where is your code? "My code doesn't work" without posting the code won't even get you sympathy here.

Ouch! Lesson learned :blush:, apologies all.

The reason I hadn't posted code is that my question was in regard to the use of the library, not a specific piece of code. However, here is the code that I was attempting to wrangle:

#include <LedFlasher.h>

// set up LEDs
LedFlasher grpA (8, 20, 40);
LedFlasher grpB (9, 20, 40);
LedFlasher grpC (10, 20, 40);
LedFlasher trans1Led (11, 1950, 50);
LedFlasher trans2Led (11, 1950, 50);
LedFlasher beacLed (12, 1500, 500);

void setup() 
{      
  beacLed.begin ();
  trans1Led.begin ();
  grpA.begin ();
  delay (20);
  grpB.begin ();
  delay (20);
  grpC.begin ();
  delay (160);
  trans2Led.begin ();
}

void loop() 
{
  // update leds
  grpA.update ();
  grpB.update ();
  grpC.update ();
  trans1Led.update ();
  trans2Led.update ();
  beac.update ();
}

My (obviously misdirected) thought was that by adding the delays at the setup stage I'd offset the start time for each instance of the class. However, what I found was that only the first delay (20ms between grpA and grpB) was actually having any effect. All instances apart from grpA were started from the same point (20ms after grpA).

I did notice that there is a fourth parameter for each instance that is a true/false boolean for whether the instance is active or not, but for the life of me can't work out how to change it in the loop, and then only the once to trigger it after a set time (using millis).

I can write the whole sketch using timers for each flash event I think, but was hoping to be able to use Nick Gammon's library (because I hate reinventing the wheel!).

Google seems to be having a real brain fart this morning. You'll need to post a link to the LedFlasher library.

Thanks Paul, this is where I got my copy:

http://gammon.com.au/Arduino/LED_flasher.zip

It's from Nick Gammon's site: Gammon Forum : Electronics : Microprocessors : How to do multiple things at once ... like cook bacon and eggs.

Looking at the code, I don't see any reason why the cycle for one set of LEDs would have a staggered start, but the cycle start time for the others wouldn't.

However, I think I'd use the on() method to start a group, rather than the begin() method.

Thanks Paul. I'll try out the on() method later after getting home. Sorry for not responding to your advice earlier but our company firewall suddenly took it upon itself to bar any access to forums or "social media activities" five hours before it was due to!!

I'm not too familiar with the structure of libraries yet, even though I do use several, so I think I'd better find out a bit more about them. That'll allow me to find out all the procedures within them.

Thanks again!

In case you want to try another way of doing this, look at the Multiblink example in the code repository below..