# Problem using interrupts

**URL:** <https://community.particle.io/t/problem-using-interrupts/27288>\
**Category:** General\
**Created:** [November 16, 2016, 3:40am UTC](https://community.particle.io/t/problem-using-interrupts/27288 "2016-11-16T03:40:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrrobert](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@mrrobert](https://community.particle.io/u/mrrobert)\
**Post date:** [November 16, 2016, 3:40am UTC](https://community.particle.io/t/problem-using-interrupts/27288/1 "2016-11-16T03:40:13Z")

</div>

![](https://us1.discourse-cdn.com/flex026/uploads/particle/original/2X/a/abcbe33edb3b77c8eaaf049d29646316f3f34f6a.png)

I am getting an error message when I try to attach an interrupt to D3. I can call scale.tare otherwise but it wont let me here. Any ideas why?

If the rest of the code will help let me know and I will post it.

Thanks!

---

<div class="post-metadata">

**Author:** ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)\
**Post date:** [November 16, 2016, 3:49am UTC](https://community.particle.io/t/problem-using-interrupts/27288/2 "2016-11-16T03:49:51Z")

</div>

It looks like you are trying to attach a class method to an interrupt and that is different from a function. Can you try wrapping scale.tare() up in a function and attach that instead?

---

<div class="post-metadata">

**Author:** ![mrrobert](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@mrrobert](https://community.particle.io/u/mrrobert)\
**Post date:** [November 16, 2016, 3:52am UTC](https://community.particle.io/t/problem-using-interrupts/27288/3 "2016-11-16T03:52:30Z")

</div>

you are right I think… that is a class method. I try and change it over to a function and see if that works! Thanks

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [November 16, 2016, 7:33am UTC](https://community.particle.io/t/problem-using-interrupts/27288/4 "2016-11-16T07:33:31Z")

</div>

You can use object methods, but you’ll need to use this overload of `attachInterrupt()`  
[https://docs.particle.io/reference/firmware/photon/#attachinterrupt-](https://docs.particle.io/reference/firmware/photon/#attachinterrupt-)

```cpp
class Robot {
  public:
    Robot() {
      pinMode(D2, INPUT_PULLUP);
      attachInterrupt(D2, &Robot::handler, this, CHANGE);
    }
    void handler() {
      // do something on interrupt
    }
};

Robot myRobot;

```

This takes the function pointer of the class method and the instance pointer of the respective object.
