Use attachInterrupt with a class method / function?

As PaulS pointed out, of course you can't.

A method has an implied "this" which is the instance of the class. Trying to make it into a static function discards which instance you are talking about.

Look, imagine you were told that if you hear bell, go and feed "the dog" when there are 20 dogs outside. Which one would you feed? But if you were told to "feed Fido" (an instance of the dogs - that is, one dog) then you can do it.

Now you can do this in C++ by using "glue" routines, providing you identify in advance which instance you want. For example, someone might tie a ribbon around Fido and say "when you hear the bell, feed the dog with the ribbon".

So your glue routine might know which instance to call.

1 Like