Possible error in FunctionDeclaration topic page.

I'm sorry if I'm mistaken, since I don't own an Arduino, have never played with microcontrollers (but want to learn!), and have little programming experience, but in the code for the example function

int ReadSens_and_Condition(){
  int i;
  int sval = 0;

  for (i = 0; i < 5; i++){
    sval = sval + analogRead(0);    // sensor on analog pin 0
  }

  sval = sval / 5;    // average
  sval = sval / 4;    // scale to 8 bits (0 - 255)
  sval = 255 - sval;  // invert output
  return sval;
}

shouldn't the line

sval = sval + analogRead(0)

actually be

sval = sval + analogRead(A0)

to denote the analog pin 0? I realize it's already using the analogRead() function, but all the other example code I've read on the site uses this method. Might be better to stick to one or the other to help clarify to neophytes like me.

Sorry if I'm mistaken.

Isn't the analog in the function name sufficient to indicate that an analog pin is involved?

There is no pin numbered A0. There is one numbered 0. Two, in fact - one analog and one digital.

One might define a name A0, using the #define compiler directive, or define a variable named A0, but the posted code snippet does not indicate that that was done. There are enough confused newbies as it is. having everyone paste that snippet into a sketch, and then wonder why A0 was "not declared in this scope" would only add to the confusion.

The code is correct as-is.

In that case there's a lot of error-filled code in the examples in the reference. For example, in the Analog Input tutorial is uses A0 to denote the analog pin.

int SensorPin = A0

And in the Calibration Tutorial is also uses

const int sensorPin = A0

and both use the analogRead() function. Perhaps those should be clarified. Since it was in several examples I figured this was the appropriate way it was used. A lot of other example code uses the same method too.

Well, I went and looked, and there are predefined #define statements that create the A0 through A5 aliased, added in version 19. However the value assigned to the variable A0 is 14, which is how an analog pin used as a digital pin is addressed.

I'm afraid I don't understand your statement that "which is how an analog pin used as a digital pin is addressed.". If the analog pin is receiving an analog input, like from the potentiometer, isn't it just being used as an analog pin, and not a digital pin, which would just receive an on or off value? Or are you referring to the analog value measured being converted into a digital value, like 0-1023? Bear with me, I'm just trying to learn.

If you want to connect more digital devices, like LEDs or switches to an Arduino than you have digital pins, you can use the analog pins as digital pins. They are then numbered 14 through 19, on the boards other than the Mega.

So, the A0 variable is an alias for an analog pin being used as a digital pin, not as an analog pin.

So, analogRead(A0); is not correct, but digitalRead(A0) is.

Ahhh, I see. Thanks for the explanation. Then, does that mean the tutorials need to be changed, since they are taking analog inputs, like the pot, but are addressed as analogRead(A0) instead of analogRead(0)?