0

Is it possible to register a class instance member function with Arduino's Wire.OnReceive?

I'm trying to make my code object-oriented, and want a specific non-static class function to handle I2C data, but if I'm reading this thread correctly, onReceive is incompatible with classes since it only accepts a function pointer, which won't store context.

1 Answer 1

0

A non-static class member function has an implicit ClassName *this parameter inserted as the first parameter in the parameter list.

Because the function prototype required for Wire.onReceive() does not have that parameter specified in its parameter list a non-static member function is not compatible with it.

The same goes for attachInterrupt() and anything else that takes a function pointer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.