Can't use attachInterrupt in a library

前端 未结 4 960
眼角桃花
眼角桃花 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条回答
  •  猫巷女王i
    2021-01-13 12:23

    So the compiler (not the IDE) tells you exactly what's wrong:

    argument of type 'void (HCSR04Interrupt::)()' does not match 'void (*)()
    

    So, while attachInterrupt() takes a function pointer of type void (*)(), you're trying to pass it a non-static member function, which you can't. You can try making the member function static and casting:

    static void echoHigh();
    
    // ...
    
    attachInterrupt(_echo_pin - 2, reinterpret_cast(&echoHigh), RISING);
    

提交回复
热议问题