Analog Outputs
A few of the digital pins—namely digital pins 3, 5, 6, 9, 10, and 11—can provide variable
output other than just 5V or nothing. These are the pins on the board with a ~ or “PWM”
next to them. PWM stands
for Pulse Width Modulation, which refers to the means of
controlling the amount of power at the output. It does so by rapidly turning the output on
and off.
The pulses are always delivered at the same rate (roughly 500 per second), but the
length of the pulses is varied. If you were to use PWM to
control the brightness of an
LED, then if the pulse were long, your LED would be on all the time. If, however, the
pulses
are short, then the LED is actually lit only for a small portion of the time. This
happens too fast for the observer even to tell that the LED is flickering, and it just appears
that the LED is lighter or dimmer.
Before you try using an LED, you can test this out with your multimeter.
Set the
multimeter up to measure the voltage between GND and pin D3 (see
Figure 6-11
).
Now upload sketch 6-08 to your board and open the Serial Monitor (see
Figure 6-12
).
Enter the single digit
3
and press Return. You should see your
volt meter register about
3V. You can then try any other number between 0 and 5.
the desired voltage (0 to 5) by 51. (Readers may wish to refer to Wikipedia for a fuller
description of PWM.)
You can set the value of the output by using the function
Dostları ilə paylaş: