attachInterrupt use within a library question

hello, newbie question (I have searched google + arduino forums but do't understand the responses, and am stuck).

Can someone please explain the use of attachInterrupt, especially with regards to the ISR within a library. I have tried various things, and keep having errors of various flavours being provided, thanks in advance.

basically I am trying to write a class to enable various pins on the Arduino DUE , and within which I have tried to setup interrupts to call a few ISR's when the interrupts occur.

I am basically trying to calculate the time elapsed between pulses from a variable reluctance sensor (via an LM1815)

I have tried a few different variants now, but the code within the class is essentially the following:

attachInterrupt(_1VRSenPin, Update1VR, CHANGE);

the code within the ISR function is essentially:

void Inputs::Update1VR(){
   TimeNow = micros();
  if( TimeNow > 1VRSenTimeOld)
   {
   1VRSenDT = TimeNow - 1VRSenTimeOld ;
   1VRSenTimeOld = TimeNow;
   }
   else
   {
   1VRSenTimeOld = TimeNow; // if you're wondering this is the one way I thought
// I could deal with timer micros() overflow, given I don't expect much variance
// from one VR pulse to the next because of inertia in the object I'm measuring.
   }

Can someone please explain to a newbie the use of the ISR function within a library?

I've looked at a few libraries that contain interrupts now and just cannot seem to understand the ISR bit, I've tried it as it's function within the library and within the class and I'm still having errors thrown up.

Imagine that you have a room full of people, each of whom can answer the door when the door bell rings. The door bell is an interrupt. The answerTheDoor() method of the person class is what is to be called when the interrupt happens.

The doorbell rings. Which person's answerTheDoor() method should be called?

When you can answer that, you'll know how to structure your class, so that the class has an answerDoor() method (that can be triggered by the interrupt) and the class is responsible for calling the correct person's answerTheDoor() method.

The answerTheDoor() function is a per instance method. The answerDoor() method is a per class method. That is it declared static so that there is only one instance. That method can be used in attachInterrupt(). But, that method mush determine which instance of the class to call the answerTheDoor() method for.

Typically, that would involve instance's registering as the active instance, like a hotel has an active doorman to answer the door bell. The hotel would have several doormen, but only one at a time is responsible for answering the door.

You might find this of use: http://hacking.majenko.co.uk/self-tracking-library

Thanks for the replies PaulS & Majenko,

Majenko, your site makes reference to a "Change Notification library", but I can't seem to see it listed, is it available to have a look at?

I'll have a work through the code + your explanations this evening, thanks again both of you,

robertspark:
Thanks for the replies PaulS & Majenko,

Majenko, your site makes reference to a “Change Notification library”, but I can’t seem to see it listed, is it available to have a look at?

I’ll have a work through the code + your explanations this evening, thanks again both of you,

It is, though it’s specifically for PIC32 based boards, not Arduino boards, so best if you just ignore that bit.