Arduino Delay

Arduino Delay

1159
0
SHARE
arduino delay

Arduino Delay with example provided in the Arduino IDE

arduino delay

The Arduino IDE includes an example of using the delay() which we will use. The basic example for delay() is been shared in the tutorial.

Function : delay()

Description

When you use delay function the program stops and nothing happens during the delay for specified time.
Arduino delay Pauses the program for specific amount of time (in miliseconds) that is been specified as parameter. (There are 1000 milliseconds in a second.)

Syntax

delay(ms)

Parameters

ms: the number of milliseconds to pause (unsigned long)

Returns

nothing

Example

int ledPin = 13; // LED connected to digital pin 13

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

void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}

While it is easy to create blinking LED program with the delay() function, many sketches use short delays for such tasks as switch debouncing, but the use of delay() in a sketch has significant drawbacks.

During delay no other reading of sensors, mathematical calculations, or pin manipulation can go on, so it brings other activity to a halt. For alternative approaches to controlling timing you can use the millis() function.

Knowledgeable programmers usually avoid the use of delay() for timing the events longer than 10’s of milliseconds unless the Arduino sketch is simple.

Buy Arduinohttp://robokitsindia.com/offers/

NO COMMENTS

LEAVE A REPLY