Analog input wont dim led? Just powers on and off.

Hey guys! I was going back to the arduino but for some reason my code wont dim the led? It just powers on and off after a certain amount of time.

int led = 2;
int button = 3;
int analog = A1;

void setup() {
  pinMode(led, OUTPUT);
  pinMode(button, INPUT);
  pinMode(analog, INPUT);
  Serial.begin(9600);
}

void loop() {
int analogInput = map(analogRead(analog), 0, 1023, 0, 255);
Serial.println(analogInput);
  if(digitalRead(button) == HIGH){
    digitalWrite(led, analogInput);
  }else{
    digitalWrite(led, 0);
  }

 /* if(digitalRead(button) == HIGH){
    Serial.println("ON - POWER: " + analogInput);
  }else{
    Serial.println("OFF - POWER: " + analogInput);
  }
  */
  delay(20);
}

Did you write to an analog capable pin?

digitalWrite(led, analogInput);

Have you taken a look at digitalWrite() - Arduino Reference to see what digitalwrite requires as an input parameter?

Description
Write a HIGH or a LOW value to a digital pin.

If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.

If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable (LOW) the internal pullup on the input pin. It is recommended to set the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor. See the Digital Pins tutorial for more information.

If you do not set the pinMode() to OUTPUT, and connect an LED to a pin, when calling digitalWrite(HIGH), the LED may appear dim. Without explicitly setting pinMode(), digitalWrite() will have enabled the internal pull-up resistor, which acts like a large current-limiting resistor.

Which, to me, shows that using analogInput as one of the input parameters is not the correct way.

That was so strange, I didn't even see it! Yes, you can't write analog values using digital write!

Heh im dumb, why did I use a digitalWrite....... thanks....