O'Reilly logo

Beginning Arduino Programming by Brian Evans

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Analog Functions

The analog functions are a little different from the digital ones. First, as we discussed earlier, they do not need to be set up using pinMode() beforehand. Second, we are dealing with integer numbers that range from 0 to 255 or 0 to 1023, rather than digital states like HIGH and LOW, so we need to keep that in mind while working with them. So anyway, let's proceed onward with a discussion of the analog functions.

analogRead()

The counterpart to the digitalRead() function, analogRead() is equally as simple at first. Its syntax follows:

analogRead(pin)

When we call this function, we need to specify the analog pin that we are reading data from, in the format of A0–A5. The “A” is placed in front of the pin number to remind us ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required