What's the difference between analogWrite and digitalWrite?
digitalWrite will set the specified pin to one of two states - HIGH/LOW, which equate to 5v (3.3v on some boards) and ground respectively.

analogWrite can vary by the type of output used.

If applied to a PWM pin - it will set the pin to a periodic high/low signal, where the percentage of the signal spent high is proportional to the value written.
for example  -

    analogWrite(PWMpin,255)


Will be HIGH 100% of the time, while

    analogWrite(PWMpin,127)


Will be HIGH 50% of the time, and LOW 50% of the time

When applying analogWrite to a DAC pin (available on some boards, like the DUE or MEGA)
analogWrite will actually cause the specified pin to output a voltage level proportinal to the specified analog value

For example, on the Due, with maximal voltage of 3.3v and a default analog resolution of 8 bits -[0:255]

    analogWrite(DACpin,255)


Will cause the specified pin to output 3.3v, and-

    analogWrite(DACpin,127)


Will cause the specified pin to output 1.35v