The milis collide if the values are the same

Why is the code below the 2nd LED not blinking. How to solve that with the same milis values?

const int ledPin =  LED_BUILTIN;
const int ledPin2 =  D2;
int ledState = LOW; 
unsigned long previousMillis = 0;
const long interval = 1000;
unsigned long previousMillis2 = 0;
const long interval2 = 1000;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
}

void loop() {
  if (milis() - previousMillis >= interval) {
    previousMillis = milis();
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }
    digitalWrite(ledPin, ledState);
  }

  if (milis() - previousMillis2 >= interval2) {
    previousMillis2 = milis();
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }
    digitalWrite(ledPin2, ledState);
  }
}

There are two variables for everything, except....

Spelling: millis()

Yes, I want to fire 2 lights but different milis variables and same running time. That is what I want

Why is the code below the 2nd LED not blinking.

Because the code has serious errors.

Post code that compiles and uploads without errors, and tell us what goes wrong, if anything.

You've got two LEDs but only one ledState variable. That's probably not what you want....

This is such a common question on here several people got together and wrote a tutorial all about blinking multiple LEDs with millis()

Millis() cannot 'collide' in any way.

Spelling: millis()

mike india lima lima india sierra :sunglasses:

because OP needs two different millis variables... :slight_smile:

Because this code does not compile.

...and even when it does you will need an ledState2 variable.

Think. How many time of day are there? One. It's all anyone needs to time as many things as they need. Similarly, you only need one millis().

Yes, I'll give it a try and find out why it can't create mailing lists at the same time, only with different variables. For example, you like the code below. So the led light will still be in the low position without blinking at all

unsigned long previousMillis1 = 0;
const long interval1 = 1000;
unsigned long previousMillis2 = 0;
const long interval2 = 1000;

void loop() {
   if(millis() - previousMillis1 >= interval1) {
      previousMillis1 = millis();
         lcd.clear();
         lcd.setCursor(0,0);
         lcd.print("test");
   }

  if (milis() - previousMillis2 >= interval2) {
    previousMillis2 = milis();
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }
    digitalWrite(ledPin, ledState);
  }
}

Oh, no!

No... because there is no such function as...

so it still won't compile. Do you understand why?

Is it because I implemented the milis() function without creating a variable?

Where did you implement the milis() function? Please post the code for it.

Or did you mean to use the millis() function, but spelled it incorrectly?

No, it's because you spelt millis() wrong.

Posts #4, #9, #14, #15, #17, and now #18 are all trying to tell you that.

Like this?

  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis1 >= interval1) {
    previousMillis1 = currentMillis;
 }

Well you now have millis spelt correctly... so that's a start.

Does your full program now compile? Does it do what you want?