checking the "mode" of a pin

Hi guys..

wonder if you can help me. I want to write an arduino sketch the check whether the pins are defined as an input or output. basically, if I set the pins like this:

int in1 = 2;
int in2 = 3;
...
...
int out1 = 10;
int out2 = 23;
...
...

pinMode (in1, INPUT);
pinMode (in2, INPUT);
pinMode (in3, INPUT);
...
...
pinMode (out1, OUTPUT);
pinMode (out2, OUTPUT);
pinMode (out3, OUTPUT);
...
...
...

... then later on in the sketch, I want to write a for loop, to go through all the pins and check whether they were defined as an inputs or outputs for example:

for (int i=2; i <= 54; i++){
if (Pins[x] == input) {
foo
}
if (Pins[x] == output {
foo1
}
}

is there a way via an IF statement to check whether the pin was defined as in or output ?

Thanks.

read about PORTs and esp. the DDRx one

(but as you set them yourself, you should know how they are set anyway...)

An easy way to deal with it could be that you define

const byte pinsAsInput[] = {2,3,...};
const byte pinsAsOutput[] = {10,23,...};

Then in the setup do a for loop to set the ones as Input, another loop to set the ones as output.

then later in your code you have 2 arrays of all the pins you care about and their mode...

In addition I can't see what you might use the knowledge of the mode setting for. If you want a pin to have a particular mode just set it with pinMode().

...R

When you find yourself doing this:

int in1 = 2;
int in2 = 3;
...
...
int out1 = 10;
int out2 = 23;

it is time to learn about arrays.

vaj4088:
When you find yourself doing this:

int in1 = 2;

int in2 = 3;
...
...
int out1 = 10;
int out2 = 23;




it is time to learn about arrays.

thanks, gonna look into arrays, i think it can do what i need.