Examples

| Led blink using millis() by BARRAGAN <http://barraganstudio.com> Demonstrates how to blink an LED at an interval rate using a timer Created March 10 2008 |

    // Led blink using millis()
    // by BARRAGAN <http://barraganstudio.com>

    int ledPin = 48;
    int status = LOW;
    long previousTime = 0;
    long interval = 5000;

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

    void loop()
    {
     // if current time - previousTime is greater than 5 secs change the LED status
     if((millis() - previousTime) > interval) {
       previousTime = millis();   // update previousTime
       // invert the LED status
       if (status == LOW) {
         status = HIGH;
       } else {
         status = LOW;
       }
       digitalWrite(ledPin, status);
     }
    }