Go Down

Topic: analog pin name in variable (Read 887 times) previous topic - next topic


Say just for example I wanted to read all of the analog pins as digital with a loop. For example:

Code: [Select]
int buttonPin[6] = {
void setup(){

void loop(){
  for (int i=0;i<6;i++){

I went ahead and just tried this and it worked... Is this the proper way to do this?



The A0, A1, etc. "names" are just #define's into existence. The value depends on the board. For a 328 based board, A0 and 14 are equivalent. So, what you did was perfectly acceptable.
The art of getting good answers lies in asking good questions.


Ohhhhh I was really surprised that it worked. That makes perfect sense. Thanks.


You may want a second loop in setup to make sure they're inputs ( they are, by default, but if you wanted outputs, you could lose some hair chasing that down)
"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.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131