TimerBlink \ Learning \ Wiring ALPHA 1.0
Author: Hernando Barragán
Description: Wiring is an electronic sketchbook and hardware electronics for developing ideas. It is a context for learning fundamentals of computer programming and prototyping with electronics within the context of the electronic arts.
Keywords: Wiring, Processing, Interactive Media, Electronic Arts, Programming, C, C++, Hernando Barragán

Search wiring.org.co:

This example is for Wiring version 0024+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.

Led blink using millis() by BARRAGAN
Demonstrates how to blink an LED at an interval rate using a timer

    int ledPin = 48;                // onboard LED
    int status = LOW;               // led status, initially LOW
    unsigned long previousTime;     // timer variable
    int interval = 5000;  // interval for blinking 5 seconds

    void setup()
    {
      pinMode(ledPin, OUTPUT);
      previousTime = millis();  // mark the time
    }

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