Hi, I am having a hard time knowing the functions of the two commands analogRead and Serial.println, specifically when they are used like this:
Ex.
pinMode(1, INPUT);
int analogValue = analogRead(1) // line 1
Serial.println(analogValue); // line 2
According to my understanding, the analogRead command reads the value of pin 1 and assigns it to the analogValue variable as seen in line 1. In line 2 the command Serial.println prints the value of the analogValue variable.
What is the purpose of printing analogValue and is it related to the first line in any way?
Does this apply only when I use an analog sensor?
By the way, I got this from this site about programming a servo motor.
What is the purpose of printing analogValue and is it related to the first line in any way?
Because sometimes, you want to know what the analog sensor's value is, and you wan't to be told on the Serial monitor.
pawle:
2) Does this apply only when I use an analog sensor?
By "this" do you mean reading analog sensors? Then yes, reading analog sensors only applies when you use analog sensors. If by "this" you mean, printing the value of a sensor, then no, you can print the value of a digital sensor as well.