Analog Write

Analog Write with Arduino

PWM stands for Pulse Width Modulation. We can use this to simulate an analog output. This is not really an analog output, but a digital approximation of analog. Basically it sends signals of varying lengths causing our led to be on and off for varying lengths of time... What the heck is that supposed to mean? Basically we flash an LED very fast, so fast you can't tell it's flashing. The more time that is spent "off" the dimmer it will appear to our eyes. Not all pins are capable of PWM. The pins that are, are labeled on your boards (pins: 3,5,6,9,10,11). 

PWM can have values ranging from 0 - 255 (256 possible states). When set to zero the led will be off, when set to 255 the LED will be at its brightest. If you put in a number higher than 255 the Arduino will still use it, however it will not be brighter. Basically it will "wrap", so 256 will be interpreted as 0 and the LED will be off, 267 will behave the same as 10 and so on.

In the sketch below, you can see a for loop. It starts at zero and increases to 255 in increments of 5.
fadeValue+=5 means fadeValue=fadeValue+5 (it's the lazy easy way of writing it).