LED double flashing

@niicoo001

you can check my Noiasca Took Kit for LEDs .

The rhythm led can be used for this double(tripple) blinking.

See the example led/0112_rhythm_led for several effects:

/*
  Rhythm LED

  a LED blinking/strobe  in a 4 sequence blinking according to ECE 2
  change the effect with a button press

  The times according to ECE2 are:
  ON    OFF   ON   OFF
  150,  60,   20,  270

  by noiasca
  2022-01-17
*/

#include <Noiasca_led.h>               // download library from http://werner.rothschopf.net/microcontroller/202202_tools_led_en.htm
#include <Noiasca_button.h>            // some tools to read buttons

RhythmPin rhythmLed {13};              // declare LED and assign pin
Button button[] {A0, A1, A2, A3};      // button connects pin with GND, "active LOW"

byte currentEffect = 0;                // this sketch allows to switch through different effects

void setup() {
  Serial.begin(115200);

  rhythmLed.begin();   // you have to call the .begin() method for the LED
  rhythmLed.on();      // you can switch the effect on

  for (auto &obj : button)
  {
    obj.begin();   // you have to call the .begin() method for each button
  }
}

void loop() {
  // read the buttons
  if (button[0].wasPressed())
  {
    Serial.println(F("button 0 was pressed, switch ON LED"));
    rhythmLed.on();  // switch on LED
  }
  if (button[1].wasPressed()) {
    Serial.println(F("button 1 was pressed, switch OFF LED"));
    rhythmLed.off(); // switch off LED
  }
  if (button[2].wasPressed()) {
    Serial.println(F("button 2 was pressed, toogle LED (change from ON to OFF or vice versa)"));
    rhythmLed.toggle(); // if button was pressed, toggle (change state) of blinkLed
  }
  if (button[3].wasPressed()) {
    currentEffect++;
    if (currentEffect >= 4) currentEffect = 0;
    Serial.print(F("button 3 was pressed, currentEffect="));
    Serial.print(currentEffect);
    // you can modify the interval in sequence of ON, OFF, ON, OFF
    // the function takes the parameters in pairs (2, 4, 6 or 8 values)
    switch (currentEffect)
    {
      case 1 :
        Serial.println(F(". ECE 1"));
        rhythmLed.setInterval(180, 320);                        // ECE 1   ON = 180ms, OFF = 320ms
        break;
      case 2 :
        Serial.println(F(". HELLA 3"));
        rhythmLed.setInterval(25, 25, 25, 25, 25, 375);         // HELLA 3
        break;
      case 3 :
        Serial.println(F(". HELLA 4"));
        rhythmLed.setInterval(40, 40, 40, 40, 40, 40, 40, 220); // HELLA 4
        break;
      default :
        Serial.println(F(". ECE 2"));
        rhythmLed.setInterval(150, 60, 20, 270);             // ECE 2 --> default
        break;
    }
  }

  rhythmLed.update();   // you have to call update() for each LED
  // put other non blocking code here, to run repeatedly
}

the minimal example is something like:

#include <Noiasca_led.h>               // download library from http://werner.rothschopf.net/microcontroller/202202_tools_led_en.htm
RhythmPin rhythmLed {13};              // declare LED and assign pin

void setup() {
  rhythmLed.begin();   // you have to call the .begin() method for the LED
  //                    ON   OFF   ON   OFF
  rhythmLed.setInterval(100, 150, 100, 1500);
  rhythmLed.on();      // you can switch the effect on
}

void loop() {
  rhythmLed.update();   // you have to call update() for the LED
}

it should be very easy to introduce more LEDs.

Could you possibly show me an example code, how it would look like with two LEDs that should start blinking at the same speed but at different times? I can't implement the tip with the state machines because I'm not sure how you mean it.

Does this do what you need, or something close?

const byte ledPins[3][2] = {
  {2, 3},
  {4, 5},
  {6, 7}
};
const unsigned long onPeriod = 100;
const unsigned long offPeriod = 200;

void setup() {
  for(byte j=0; j<3; j++) {
    for(byte k=0; k<2; k++) {
      pinMode(ledPins[j][k], OUTPUT);
    }
  }
}

void loop() {
  for(byte j=0; j<3; j++) {
    for(byte f=0; f<2; f++) {
      for(byte k=0; k<2; k++) {
        digitalWrite(ledPins[j][k], HIGH);
      }
      delay(onPeriod);
      for(byte k=0; k<2; k++) {
        digitalWrite(ledPins[j][k], LOW);
      }
      delay(offPeriod);
    }
  }
}

I had that at the very beginning with delay() too.
I would like the flashes of the LED pairs to overlap.

You're going to have to explain in more detail what you mean by overlap.

The video your posted didn't show any overlap that I could see.

Please clarify what it means?

It's hard to clarify, I know.
The video is not exactly how I would like to implement my model. I will try to explain it again:

For better understanding I now have two LEDs - LED A and LED B.
LED A flashes twice and then there is a pause. As the code from post #11 already implements.
While LED A flashes twice, LED B should start after the first flashing of LED A with two flashes and then a pause. LED B should flash at the same speed.

I hope that makes it more understandable.

At the same time, I would also like to flash another LED twice at a different speed.

Could you help me with these two problems?