I need to use some different pins that have been defined in a library. I do not want to edit the library as I will no doubt forget about the mods when using it on another board or another project.
Can I #define the pins in the .ino file and expect it to ovreride the definitions in the library ?
As further clarification can anything be overridden in the library by .ino statements (providing the classes in the lib are public) ?
I trust this makes sense, last time I did any C programming was in C, C++ hadn't been invented and even my C was during night classes, Pascal, FORTRANand COBOL, well now we're talking.
Can I #define the pins in the .ino file and expect it to ovreride the definitions in the library ?
Why not try it yourself ? Put the #defines in a sample sketch that includes the library then print the values. What do you get, the values from the library or the values from the .ino ?
For the OP, it would be safest to precede the new #define with an #undef, to make sure the compiler forgets the first one and make it clear that this is your real intention and you did not re-define by mistake.
RichardM:
I need to use some different pins that have been defined in a library. I do not want to edit the library as I will no doubt forget about the mods when using it on another board or another project.
It should be possible to change the library in a backwards compatible way, by extending the API to let the pin numbers be specified at runtime i.e. passed in to the library from the sketch, and defaulting to the standard ones.
Alternatively, but far less elegant, you could create a clone of the library with the hard-coded values changed.
There are no easy solutions to change the pin numbers used inside the library's implementation without changing the library source code. The non-easy options would involve changing compiler options for your sketch, which in practice would not solve the underlying problem since you'd be left needing to set sketch-specific compiler options which would be even less maintainable than modifying the library.
Well, you certainly can override a previously defined symbol.
Something like this:
// this definition occurs "somewhere" in your project (maybe in a library)
#define PIN 1
// this is your code, and you want to redefine PIN
#ifdef PIN
#undef PIN
#define PIN 2
#endif
This assumes that the Arduino sketch preprocessor behaves in the same way as conventional compilers - it certainly doesn't raise any warnings or errors during verification.
Whether or not you can do this to affect the library behaviour is questionable though. If the library's #define is in a code file rather than a header, you're out of luck. If it's in a header then it will depend on the order of #includes in the code file that uses the defined symbol, and you would need to do the redefinition in a later #include (which may cause further problems if this means hacking an Arduino header).
The only way to be sure is to fork the library and create your own version.