-
Notifications
You must be signed in to change notification settings - Fork 72
Mike Schwager edited this page Oct 6, 2015
·
13 revisions
-
The EnableInterrupt library does not work with *Insert name of other library here*
- True, the library specifies the ISR's for all the Pin Change and External interrupt vectors.
-
No really, the EnableInterrupt library does not work with the Software Serial library.
- Don't use that library. Use Paul Stoffregen's AltSoftSerial library at https://github.com/PaulStoffregen/AltSoftSerial.
-
Yeah but what is the downside of the AltSoftSerial library?
- It uses one of the ATmega's timers. Other than that, I think its design is far superior.
- I cannot include the EnableInterrupt library in my own library.
-
I cannot use the EnableInterrupt library with other code that uses the library.
- Yes, yes you can. First some background: As you know, the C/C++ compiler allows you to separate your
Now, by default if you use the EnableInterrupt library in multiple files, then when the Arduino software gets to linking them, it discovers that certain functions (specifically the ISRs) have already been created. It complains because it would be an error to create another one; how is it to choose which function to really run?
It seems counterintuitive to compile the library's code twice; it makes no sense to us. Indeed, I have tried the `--read-my-mind` switch on the compiler. It says,
gcc: error: unrecognized command line option ‘--read-my-mind’Drat; it doesn't work :-) . The compiler doesn't know that it makes no sense to compile code twice- it simply does what it's told. So, we have to be careful to tell the compiler *exactly* what to do. Therefore, you must insert
#define LIBCALL_ENABLEINTERRUPTin front of every `#include ` in every one of the files in which you want to use EnableInterrupt library functionality- *except one*. In that file (often but not necessarily your sketch), just place the `#include` directive; don't define the `LIBCALL_ENABLEINTERRUPT`. Then for that one file only the compiler will create the Arduino code and it will then link all references to its functions as necessary. The compiler is no longer confused since there is only one set of compiled code for the library.
-
I want to use the EnableInterrupt library to interrupt on Analog signals.
- Sorry, that's not supported by the Arduino's interrupt system. Obviously, then, the library
-
I want to attach multiple function to a single pin.
- Sorry, only 1 function per pin. If you need to call multiple functions then just have your