Pulse Width Modulation
Technique used in motor speed control, lighting, sound generation, and servo positioning.

Since getting analog voltages out of a binary device requires extra hardware, sometimes just sending out a stream of pulses with the percentage of on-time correct will work.
For example, to get an output voltage of 3 volts from a pin that can be either at 0 or 5 volts, having the pin at 5 volts 60% of the time (plus a filter capacitor) gets you close to 3V.

For all the elegance and thrift of this approach, there is a lot of processor overhead in deciding exactly when to switch while doing other tasks. Some microcontrollers have special hardware to do PWM in the background.