I am building a CPP library (class) to manage obstacle detection using the HC-SR02 sensor. I want to have all the methods that manage this device inside a class, but this proves challenging because the attachInterrupt function cannot call outside the class. What I need is a simple example of how to do this. My goal is that I be able to easily replicate this solution into lots of robots.
Some additional information In sketch (before setup): BJMotionDetector myDetector; In Setup: attachInterrupt(0, myDetector.echoInterrupt,0); // Attach interrupt to the sensor echo input In Class: void * BJMotionDetector::echoInterrupt() Compiler output: error: cannot convert ‘BJMotionDetector::echoInterrupt’ from type ‘void* (BJMotionDetector::)()’ to type ‘void (*)():attachInterrupt(ECHO_INTERRUPT, myDetector.echoInterrupt, CHANGE)Error compiling .ino source
Do you mean the HC-SR04 sensor? Which library are you using with that sensor? The NewPing? http://playground.arduino.cc/Code/NewPing