int ledPin = 11; // select the pin for the LED
int brightness = 0;
// the setup routine runs once when you press reset:
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
//remap sensorValue from 0-1024 to 0-255
brightness = map(sensorValue, 0, 1024, 0, 255);
// set the brightness of pin 9:
analogWrite(ledPin, brightness);
Serial.println(brightness);
delay(1); // delay in between reads for stability
}