What does this do:
const int light=A6;
const int ledlight=9;
void setup()
{
}
void loop()
{
int lightval = analogRead(light) / 4;
int brightness = lightval;
analogWrite(ledlight, brightness);
}
?
Note that you don't set the pinMode of analogue input pins, and PWM output pins don't need them either, the analogWrite sets the mode.
Note: Please don't edit earlier posts to reflect the new state of code, it makes the thread hard to follow - just put the amended code in a new post.