Why does this EC sample sketch use an output?

I'm new to the whole programming business. and when i was looking at a sample sketch for a EC meter it uses an output pin. Can someone explain to me in simple terms why it does this?

Because I would like make this code smaller so i just have an output only.

Thanks

const int analogInPin = A1;  // Analog input pin that the sensor output is attached to

const int analogOutPin = 9; // Analog output pin that the LED is attached to




int sensorValue = 0;        // value read from the sensor

int outputValue = 0;        // value output to the PWM (analog out)




void setup() {

  // initialize serial communications at 9600 bps:

  Serial.begin(9600); 

}




void loop() {

  // read the analog in value:

  sensorValue = analogRead(analogInPin);            

  // map it to the range of the analog out:

  outputValue = map(sensorValue, 0, 1023, 0, 5000);  

  // change the analog out value:

  analogWrite(analogOutPin, outputValue);           




  // print the results to the serial monitor:

  Serial.print("sensor = " );                       

  Serial.print(sensorValue);      

  Serial.print("\t output = ");      

  Serial.println(analogRead(1)* 5.00 / 1024, 2);   




  // wait 10 milliseconds before the next loop

  // for the analog-to-digital converter to settle

  // after the last reading:

  delay(500);                     

}
outputValue = map(sensorValue, 0, 1023, 0, 5000);

Is this for a Due? Even so, 5000 is too high for 12 bit PWM

I use it with a UNO

godspeed: Can someone explain to me in simple terms why it does this?

It seems to adjust the brightness of the LED in proportion to the sensor value. If you don't want that just try the code without it.

...R

godspeed: I use it with a UNO

in which case, the brightness of the LED will sawtooth up and down

Thanks for all the answers.

So do I pretty much only need to keep this:

const int analogInPin = A1;  // Analog input pin that the sensor output is attached to


void setup() {

  // initialize serial communications at 9600 bps:

  Serial.begin(9600); 

}



void loop() {

Serial.print("\t output = ");      

  Serial.println(analogRead(1)* 5.00 / 1024, 2);

delay(500);   

}

Would I even need to have const int analogInPin = A1;?

because it just uses this line of code instead?

(analogRead(1)* 5.00 / 1024, 2);

Thanks.

godspeed: Would I even need to have const int analogInPin = A1;?

because it just uses this line of code instead?

(analogRead(1)* 5.00 / 1024, 2);

Thanks.

Because your sketch may grow, and it's good to get into good habits soon