The pin number has to be a pulse width modulated pin,
it has a little tilde symbol.
They're marked on the Arduino.
So an example, you might say analogWrite(3, 128).
That would say on pin 3 we're going to drive that with a square wave.
And 128 is it's duty cycle.
Now since that's halfway between, or almost halfway between 0 and
255, you'd expect a 50% duty cycle for that.
Now, here's an example piece of code.
This is actually in your example, so if you open up your Arduino IDE.
Go to file, examples, I believe this is in the basics.
File examples, basics.
There's one called Fade, and that's this.
I've taken out all the comments to make it shorter, but this is basically the code.
So, first notice there the normal two functions, the setup and the loop.
All this does, just to zip right to what it does, there is an LED.
It assumes that there is an LED connected on one of the pins.
Actually I must have left out that.
LED is a variable in here that refers to a particular pin that you've
wired an LED on to.
Let's assume it's pin 13, okay?
Say it's pin 13, cuz we know there's an LED on that pin.
So what all this does is it calls analogWrite
on that pin you can see highlighted in red.
It called analogWrite on that pin.
So it generates a square wave on that pin.
And the second argument which is the duty cycle.
Which is the indication of the duty cycle, that's the brightness.
So the idea is that if you have a large duty cycle, 100% duty cycle,
then you're gonna get a very bright LED.
But if you have a very small duty cycle,
it's only high a very small fraction of the time, then you get a very dim LED.
And so what this function does, if you look at the loop, it does the analogWrite
with a certain brightness, starting at brightness 0, so it would be off.
Then it increments brightness,
brightness = brightness + fadeAmount, which is something small, say five.