Hardware Reference
In-Depth Information
Figure 3-11. Digital is like the switch on the left, it can be either on or off.
Analog, on the other hand, can be set at a range of values between fully on
and completely off.
analogWrite()
I wrote that it's “sort of” like a dimmer switch because analogWrite() uses a
feature called pulse width modulation , or PWM, to make it seem like there's
a range of voltages coming out of the pin. What it's actually doing is pulsing
the pins on and off really quickly. So if you want the pin to be as though it's
at half voltage, the pin will be pulsed so that it is on 50% of the time and off
for 50% of the time. If you want the pin to be as though it's at 20% power, it
will turn the pin on 20% of the time and off 80% of the time. This percentage
of time that it's on versus total time of the cycle is called the duty cycle
( Figure 3-12 ). When you connect an LED to these pins and use analog
Write() to change the duty cycle, it can give the effect of dimming the LED.
Search WWH ::




Custom Search