delay()

[Timing]
void delay(unsigned long ms);

Description

Pauses the program for the specified amount of time (in milliseconds) as parameter.

Parameters

ms: time in milliseconds.

Returns

Nothing.

Example Code

The code creates a clock with the pin 2, toggling the output every 500 milliseconds (1Hz).

void setup() {
    pinLabel(2, "OUT");  // sets the pin 2 label to "OUT"
    pinMode(2, OUTPUT);  // sets the digital pin 2 as output
}

void loop() {
    delay(500);  // pauses the program for 500 milliseconds
    digitalWrite(2, !digitalRead(2));  // toggles the output of the pin 2
}

Notes and Warnings

There are no ways to avoid the delay function, it is a blocking function that stops the program execution for the specified time.