EMBEDDED SYSTEMS & MICROCONTROLLERS · PAGE 12
PWM: Pulse Width Modulation
Fake an analog level by switching fast.
PWM switches a pin on and off at a fixed frequency. The duty cycle is the fraction of each period spent high. At 25 percent duty a 5 V pin averages about 1.25 V.
LEDs look dimmer and motors run slower because the eye and the motor's inertia smooth out the fast switching. Hobby servos read the pulse width itself as a position command.
Pick a frequency high enough to avoid visible flicker or audible whine, and drive loads through a transistor.