//Arduino Mage 2560 read potentiometer and write LED
int sensorPin = A8; // connect this pin to potentiometer
int ledPin = 2; // connect this pin to external LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT); // set this pin to output
Serial.begin(9600); // start serial monitor
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
sensorValue = map(sensorValue, 0,1023,0,255);
// turn the ledPin on
analogWrite(ledPin, sensorValue);
Serial.println(sensorValue); // bright LED with read value
}