Sorry, but your question is hardly understandable. You say you want to check whether a pin has already been used in another part of the project, and in the same time you're showing code for defining macros in macros.
But that's where it hurts, like @graben showed, it's simply not possible to achieve in C. First of all both of your syntaxes are wrong:
#define P(no_,name_) PIN##name_ = no_
you're not creating a macro name PINLED
to which you assign 13
, but you're assigning to the C variable PINLED
the value 13
. To make your PIN definition macro work, you'll need to use const int
variables, which usually are easily optimized by the compiler.
Now, to get to the goal you say you want to achieve, I think it's very unlikely you can do it in macro processor code, at least in an elegant way...
And I don't think that's even necessary!
If you design well your libraries, you should not be using the pin number throughout your code and libraries, but design them so you define pins for each library at the library initialization stage. That's why usually Arduino libraries work in three steps:
- allocate the memory (which is done by calling the constructor, which is often made in the included header file as a global object) ;
- configure the instance (which is done with the
.begin()
method) - use the instance
so basically, if you have all your pins defined in the same file, you should not run into pin reuse elsewhere in your code.