Can't use attachInterrupt in a library

前端 未结 4 891
眼角桃花
眼角桃花 2021-01-13 11:58

I\'m writing a simple library for an ultrasonic distance sensor and thought i\'d try using interrupts.

However i can\'t set my functions in the attachCallback<

4条回答
  •  执念已碎
    2021-01-13 12:16

    Arduino interrupt handlers can only be functions. You are trying make method of an object an interrupt handler. Hence the compiler complains.

    To be more precise about it, object methods are like functions, but it is as if they take a "hidden" parameter, which specifies the object instance. Therefore, they actually have different type signatures from plain functions. This disallows one to pass a method pointer when what a function is looking for is a plain function pointer.

    The solution is to move your echoHigh() and echoLow() out of the HCSR04Interrupt class, and make them plain functions.

提交回复
热议问题