Book Image

Arduino Essentials

Book Image

Arduino Essentials

Overview of this book

Table of Contents (17 chapters)
Arduino Essentials
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Time control functions


The Arduino library has four functions that allow us to manage the time. We have already seen one of them, the delay() function, which we have used from our first sketch to stop the execution of the code for a short period of time.

As we saw in Chapter 3, Interacting with the Environment the Digital Way, the delay() function accepts only one parameter: the desired number of milliseconds to pause. For most projects, this resolution will be fine, but there can be situations where a millisecond is too much.

For these kinds of problems, the Arduino library also offers the delayMicroseconds() function that, as you can imagine, pauses the code execution for just the number of microseconds that you set as its only parameter.

A microsecond is a millionth of a second, or to put it another way, there are a thousand microseconds in a millisecond and a million microseconds in a second.

Due to restrictions in the Arduino architecture, the maximum delay the delayMicroseconds() function...