does anyone know how to use "attachInterrupt" in the costructor of a class declared in a library? The interrupt service routine YYY is also a method of that library. I have only found dirty methods like this one: call attachInterrupt in the setup() on the main program
attachInterrupt(0, XXX, RISING)
Put a method XXX in the main program who call the method inside the class
The attachInterrupt function can be called from anywhere. The method to call must be a static method, though. It can't be called on a specific instance. If the class contains some method of recording a specific instance to be referenced in the callback, you can access that data to get the instance, and then call other instance methods.
Here is an example of something that has worked for me but I hope can be improved. It currently works with either INT0 or INT1 as determined by the pin number passed via the constructor. I would like to also support the 4 additional external interrupts available in the Mega but to do this, I have to replicate the interrupt handler for each potential interrupt source. This seems wasteful - is there a better way?