Hardware Reference
In-Depth Information
The pin parameter is the pin number you want to read from. This function
returns either HIGH or LOW , depending on the input.
digitalWrite()
To write the state of a pin that was declared as an OUTPUT , use the digitalWrite()
function:
digitalWrite(pin, value);
The pin parameter is the pin number you want to write to, and the value is
the logical level you want to write; HIGH or LOW .
Analog I/O
Analog is different than digital. Digital signals are one of two states; either true
(a logical one), or false (a logical zero). Digital states are not designed to have
any other value.
Analog is different in that it has a potentially ini nite amount of values between
two points. Analog is all around us. A light bulb is normally either on or off,
but consider the sun. At nighttime, there is no light, and in daytime, midday,
on a sunny day with no clouds, you would think that you have the maximum
amount of sunlight. And during sunrise? You can see the amount of sunlight
change visibly within a few minutes. During a cloudy day? There is light but
not as much as during a clear day. This is no longer digital; it isn't on or off. The
sun is analog; there are an ini nite amount of possibilities.
Imagine a cruise ship. At the front of most large ships, there is a scale, a water
line . It is used for several reasons, but to simplify, this marker serves to determine
if a ship has been overloaded. Overloaded, a ship is at risk of sinking. The water
line, technically called the Plimsoll Line , is where the water meets the hull. You
can imagine that this line varies between two values: the minimum and the
maximum. For this example, imagine between 20 feet and 40 feet. Right now, the
ship you are watching is loading passengers, excited to sail to the Mediterranean.
Slowly, the Plimsoll line rises: 30 feet, 31 feet, 32 feet.... And it stops at 33 feet.
With a maximum Plimsoll line of 40 feet, this ship is safe to sail, but what is
the exact value? 33 feet? Exactly? Probably not. It might be 33 feet and 1 inch,
or maybe 33 feet and 3/8 of an inch? The point is, it doesn't matter. Humans
aren't good with an ini nite amount of values, and a docker looking at the ship
will i ll in the registry with 33 feet; he won't need absolute precision. It doesn't
matter if a little bit is lost in the process.
Microcontrollers work in the same way. Microcontrollers are digital, but
many can read analog values, including Arduinos. The device used to read
analog is called an ADC , short for Analog to Digital Converter . The ADC cannot
handle ini nite values. It has a resolution . The Arduino divides the range into
 
Search WWH ::




Custom Search