You'll have to explain a little bit more about what you want to do. What are the conditions you want to define for each of those LEDs?
[quote author=Runaway Pancake link=topic=102535.msg769208#msg769208 date=1335121557]
const int analogPin = A0;
Is that legal in that form?
A0 - A5 correspond to 14-20
Should it then be:
const int analogPin = 14;[/quote]
Yes, that's legal syntax. There is no difference by using "A0" or "14". So I don't understand what you are questioning.
That the analogPin value is then an integer "A0"?
In past I just use analogValue = analogRead(A0);
Does the IDE differentiate/understand that using "A0" or "14" is all the same?
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
}
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.
It's a combination of the pre-processor (Ax alias) AND the actual function analogRead().
Look at the function analogRead():
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.
You might be interested in the section on "Pin Mapping":
RunawayPancake, No, you're still missing the point.
The preprocessor has no knowledge of any context of analogRead, it blindly replaces A0 with 14.
However, in the particular context of analogRead, zero and fourteen are equivalent.
Obviously, in any other context, the equivalence would not hold, you could not, for instance, write "A0 == 0" and expect it to be true.
James C4S,
So, it gets sorted - 0/A0/14 associated with analogRead yield the same result.
OK.
skeeter_mc,
Place a Serial.print or two in your 'sketch' to Debug your situation, to find out where it's getting stuck (if it's getting stuck at the analogRead, as you suggest.)
If possible, It might be appropriate to split this topic. I think the discussion on what A0 is good to keep, but it might distract the original poster.
In the first copy you replace threshold with firstthreshold and ledPin with firstPin .
In the second copy you replace threshold with secondthreshold and ledPin with secondPin.
You can probably figure the rest out ...
For a more elegent solution you would put your thresholds and LED pin numbers in arrays and put in a loop that applies each threshold.