controlling led brightness w/ pot

I thought the code below would let me control an led's brightness with a potentiometer, but a guess I was wrong because it doesn't work. Could someone help me with this simple task?

int knobvalue;

void setup()
{
pinMode(11, OUTPUT);
}

void loop()
{
knobvalue = analogRead(0);
knobvalue = map(knobvalue, 0, 1023, 0, 255);
analogWrite(11, knobvalue);
}

How are you hooking up the potentiometer and led?

Nevermind. Stupid mistake. I got it working.

int knobvalue;
int potpin = 0;

void setup()
{
pinMode(11, OUTPUT);
}

void loop()
{
knobvalue = analogRead(potpin);
knobvalue = map(knobvalue, 0, 1023, 0, 255);
analogWrite(11, knobvalue);
}

Take a look at the source code for the map function, sometime. It is a relatively inefficient means of dividing by 4.

analogWrite(11, analogRead(potPin)/4);

would accomplish the same thing that all your code in loop is doing, and do it faster.