Hi,
I am using the PinChangeInt library to set up a number of interrupts for a (relatively) arbitrary number of rotary encoders on my Arduino Uno.
I am creating my own Encoder library, which relies on the PinChangeInt library.
I have a call in my Encoder library that looks like this:
void AdaEncoder::attachInterrupt(int pinA, int pinB) {
PCintPort::attachInterrupt(pinA, encoderInterrupt, CHANGE);
}
Note the AdaEncoder::attachInterrupt() method, above, is not static. But the PCintPort::attachInterrupt() method is. I have a stub encoderInterrupt() method:
void encoderInterrupt() {}
The error I get is this:
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp:65: error: no matching function for call to 'PCintPort::attachInterrupt(int&, <unresolved overloaded function type>, int)'
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/../PinChangeInt/PinChangeInt.h:87: note: candidates are: static void PCintPort::attachInterrupt(uint8_t, void (*)(), int)
I think what I have to do is make the encoderInterrupt() method static, but I'd like to avoid that. Is there any way I can do so? Or do I need to make encoderInterrupt() static, then solve my problem by utilizing static pointers or arrays?
Page 5 of this has an example of the sort of thing you need to do (make a wrapper). You will need a static entry point, but that function can bounce to the handler specified for the individual object.
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp: In member function 'void AdaEncoder::attachInterrupt(int, int)':
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp:68: error: invalid use of void expression
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp: In member function 'void AdaEncoder::attachInterrupt(int, int)':
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp:68: error: lvalue required as unary '&' operand
I can't figure out how to pass this through my static wrapper so as to open up the world of possibilities to me! I need it so that I know which object the interrupt applies to.
I can't figure out how to pass this through my static wrapper so as to open up the world of possibilities to me! I need it so that I know which object the interrupt applies to.
You can't. Something external to the Arduino generated an interrupt. How is that external device supposed to know which object should react?
What you are trying to do makes little sense, as I understand what you are trying to do.
Perhaps if you explained just what you want to do, without code. Just the basic idea.