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
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 } }