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 ...

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.