Go Down

Topic: Changing the if() statement to use five LEDs (Read 1 time) previous topic - next topic

AWOL

The IDE has nothing to do with it; the preprocessor simply replaces A0 with the literal 14.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Runaway Pancake

OK
The 'Arduino Reference' example is:
Code: [Select]

int analogPin = 0;  //   They actually used [b]3[/b], same concept
                         //    They didn't use  int analogPin = A3; or  int analogPin = A0;

void loop()
{
  val = analogRead(analogPin);    // read the input pin
  Serial.println(val);             // debug value
}

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

AWOL

I still don't see what point you are trying to make; in this context (analogRead), zero and fourteen are completely interchangeable.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Runaway Pancake

Well, I'm not trying to make a point or be a pain - I'm trying to get it (too).
An integer = 0 and A0?  Likewise, an integer = 3 and A3?
Just didn't think I've seen analogRead with an alias declared as int = A0 (or Ax) before.
Thought that might be what's holding up the analogRead that our friend can't get past.

Well, if the pre-processor figures it all out in context then fine.
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

James C4S

Well, if the pre-processor figures it all out in context then fine.

It's a combination of the pre-processor (Ax alias) AND the actual function analogRead().


The 'Arduino Reference' example is:
Code: [Select]

int analogPin = 0;  //   They actually used [b]3[/b], same concept
                        //    They didn't use  int analogPin = A3; or  int analogPin = A0;


Look at the function analogRead():

Code: [Select]

int analogRead(uint8_t pin)
{
//... removed for clarity
       if (pin >= 14) pin -= 14; // allow for channel or pin numbers
#endif


The very first thing analogRead() does convert values like 14 (for the ATmega328) to 0.  So if you pass A0 (which is replaced with 14 by the preprocessor), 14, or 0; analogRead() treats them all the same.



Just didn't think I've seen analogRead with an alias declared as int = A0 (or Ax) before.

You might be interested in the section on "Pin Mapping":
http://arduino.cc/en/Tutorial/AnalogInputPins
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Go Up