Guidance to complete the code.

i need to turn on an LED propotional to the position of the variable resistor.i have written the following code in the normal way.Please suggest how i can change the brightness of the LED propotional to the position of the variable resistor.Thank you.

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);
}

Please suggest how i can change the brightness of the LED propotional to the position of the variable resistor.

For "variable resistor", read "potentiometer".

Why, what does it do now?

  knobvalue = map(knobvalue, 0, 1023, 0, 255);

is an expansive way of (almost) writing knobvalue /= 4;

Please remember to post code inside [code][/code] tags

The documentation for analogWrite() says: "You do not need to call pinMode() to set the pin as an output before calling analogWrite()." That would not explain your unspecified symptom.

What model of Arduino are you using? It shouldn't matter since all models seem to support analog output (PWM) on Pin 11.

How do you have the LED wired?

If you are having trouble I suggest you use two different variables so that you can print the values separately to check what is happening.

Instead of this

  knobvalue = analogRead(potpin);
  knobvalue = map(knobvalue, 0, 1023, 0, 255);
  analogWrite(11, knobvalue);

do this

  knobvalue = analogRead(potpin);
  ledvalue = map(knobvalue, 0, 1023, 0, 255);
  analogWrite(11, ledvalue);

And, just to clarify, either form of the code should work.

...R