Digital Functions

Now that we’ve seen the digital functions in action, let’s look at each of them individually in greater detail to better understand how they work.

pinMode()

Before we can put the other digital functions to work, we first need to let the Arduino know how we plan to use its digital I/O pins. To do this, we use a function called pinMode() to set up which pin we are going to use and how we intend to use it. Its syntax is fairly simple, as follows:

pinMode(pin, state)

Inside the parenthesis of the function are two values separated by a comma. The first value is the number of the pin that we are setting up. This could be a number or variable with the value ranging from 0 to 13 or A0 to A5 (if using the Analog In pins for digital ...

Get Beginning Arduino Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.