analogWrite() uses PWM or Pulse Width Modulation to control how much power is being delivered via a digital pin. PWM is a technique for getting pseudo-analog results with digital means. It does not write a true analog value. Digital control is used to create a square wave (signal switched between on & off). The average power is increased or decreased by pulsing the voltage at a very fast rate and controlling the "on" time. Used to control intensity like the speed of motors or brightness of LEDs.
analogWrite(pin, value)
- sends a PWM wave only works on pins with tilde ~ (pins 3, 5, 6, 9, 10, 11)
pin
: the Arduino pin to write to.value
: the duty cycle: between 0 (always off) and 255 (always on).