Examples

| Timer by BARRAGAN <http://barraganstudio.com> Demonstrates how to create a timer to turn ON an LED after certain time has passed since a switch is pressed Created April 30 2007 |

    // Timer
    // by BARRAGAN <http://barraganstudio.com>

    int ledPin = 48; // Wiring hardware diagnostic LED on pin 48
    int switchPin = 1; // Switch connected to the Wiring I/O board pin 1
    long previousTime = 0;

    void setup()
    {
      pinMode(ledPin, OUTPUT);   // sets the digital pin as output
      pinMode(switchPin, INPUT); // sets the digital pin as input
    }

    void loop()
    {
      if(digitalRead(switchPin) == HIGH) {  // if the switch is pressed
        previousTime = millis();		// save the actual time
      }
      if((millis() - previousTime) >= 7000 ) {  // if 7 seconds have passed since started counting
        previousTime = 0;			    // reset saved time
        digitalWrite(ledPin, HIGH);		    // turn ON the LED
      }
    }