Personally I would always put the variable on the left side of a comparison as it reads more naturally to me, especially when using and/or if((potval > 0) && (potval < 342))as it makes it easier to see the range of values being checked, at least it does to me.
Both ways work, of course, but putting the value first seems unnatural somehow.
I see an easier and more flexible way to do this than a bunch of if statements. I'd declare the ledPins in an array and then use a for loop to display them all. A value calculated from reading the pot decides whether the led is on or off. The advantage being that it becomes trivial to add more leds to the deal.
something like:
int limitValue = analogRead(potPin) / ((1024 / ledCount) + 1); // redundant parentheses for clarity
for (byte n = 0; n < ledCount; n++)
{
if (n <= limitValue) digitalWrite(ledPin[n], HIGH);
else digitalWrite(ledPin[n], LOW);
}
Then I'd probably add a variable and a condition to only update the leds if the limitValue has changed.
UKHeliBob:
Both ways work, of course, but putting the value first seems unnatural somehow.
The advantage of putting the value first comes in when you make this mistake: if ('a' = incomingChar)
[/quote]I know what you mean but I still prefer the "variable first" construction and anyway I would never make such a mistake, well not often anyway.