// assigning a name is for attached by pin 3 with a led.
int ledPin = 3;
// assigning a name is for attached by pin 0 with a analog.
int analogPin = 0;
// value for calculate the output pin
int val = 0;
// put your setup code here, to run once:
void setup() {
// make the led's pin as output
pinMode(ledPin, OUTPUT);
// setup serial communication at 9600 bits per second.
Serial.begin(9600);
}
// put your main code here, to run repeatedly:
void loop() {
// get the out pin
val = analogRead(analogPin);
// print out state of the led pin
Serial.println(val);
// re-maps a number from output pin to 8 bits (0 to 255)
val = map(val, 0, 1023, 0, 255);
// writes an analog value (PWM wave) to a output pin
analogWrite(ledPin, val);
}