Millis, LED and the story of a guy that has no idea what he is doing.

I'm trying to expand on the code blink without delay code ( ). I would like to try to make it so two different lights blink independently from each other but this just seems to make one light up no matter what I do. Mainly I wanted to do this so I could understand the function for more complex projects. The delay feature seems to be clock for the whole loop and millis seems to be for an individual if statement. I think I just don't fundamentally understand what "millis" is suppose to do. I was looking for something to provide two different loops and this is the solution that an ancient forum post gave but it doesn't seem to be working. It worked for them so I must be doing something wrong.


What is millis? What would a program with two LEDs set to different timings via millis look like?

Thank you all

No code?

Read this before posting a programming question

Read this for insights into millis:

//modified Blink without Delay by Craig C.  this simply controls pins 2 and 3
//and allows the person to blink TWO led's alternately (i'd use a 555 timer, each to
//their own) 

/* Blink without Delay

 Turns on and off a light emitting diode(LED) connected to a digital  
 pin, without using the delay() function.  This means that other code
 can run at the same time without being interrupted by the LED code.

 The circuit:
 * LED attached from pin 13 to ground.
 * Note: on most Arduinos, there is already an LED on the board
 that's attached to pin 13, so no hardware is needed for this example.

 created 2005
 by David A. Mellis
 modified 8 Feb 2010
 by Paul Stoffregen

 This example code is in the public domain.

// constants won't change. Used here to
// set pin numbers:
const int ledPin =  2;      // the number of the LED pin
const int ledPin2 =  3;      // the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);      
  pinMode(ledPin2, OUTPUT);     

void loop()
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;  

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
    digitalWrite(ledPin2, !ledState);