# Use of Macros

Hi all, I have a question?

For my sketch i want to create a sort of "hardware mask" that is an array where i store the number of I/O i used, so i can call in the code, for example, "digitalRead(hardwareMask[0]);" and give me the advantage to change the connection by only modify this array but i have a problem. If i store it in a int array i can't save on it the analog I/O (due their names are A0,A1... String tipe). So i'm looking for a solution based on macros that create a "#define hardwareMask[x]" (x=pre-defined constant) where to store the whole pins.

my question is: is that possible?? and if yes How to do that??

thx

For analogue inputs there is bono need to use the name A0 just a simple number will do.
By the way mask is the wrong word for this. Mask is used to talk about the second operand ina bit wise operation.

thx guys, about the analog equivalent number i have read that it work only if you want use an analog pin as digital only, but maybe i understand it wrong.

NOTE (not interesting): i know that "mask " is about bit operations but the name is not important i can call it "paperino"

but maybe i understand it wrong.

Yes you do.

Your first assumption that A0, A1, etc are strings is flawed, so nothing after that makes sense. A0, A1, etc. are #define'd names that are replaced by constants (numeric) before the compiler is called. The actual constant is board-specific.

On the uno D14 is the same as A0

Mark

thx guys problem solved.

Just for knowledge is possible to make a #define array[]={foo, too, boo} (foo, too, boo are costants numbers) and then use it like "int a=b+array[0];" ?

just declare a constant array:

``````#define foo 123
#define too 345
#define boo 678

const char array[] = {
foo,
too,
boo,
};
``````

If you're going to hard-code the array index values as in the examples you've shown then I don't see the point of using the array. I also question whether the constant definitions are achieving any useful abstraction since you seem to be hard-coding the array index values anyway so you're just exchanging one magic number for another.

If you posted more realistic examples showing what you're trying to achieve, we might be able to suggest more sensible ways to achieve it.

Just for knowledge is possible to make a #define array={foo, too, boo} (foo, too, boo are costants numbers) and then use it like "int a=b+array[0];" ?

No. A #define statement simply defines a name and a value. In that statement, what is the name, and what is the value? The name is array={foo, too, boo} and there is no value.

When the preprocessor runs, it substitutes the value (nothing) everywhere that the name appears (nowhere).