user23207: I'm having a bad time trying to call a correctly-working expression (ultra[currentSensor].ping_timer(echoCheck)) from an own class method (myclass::run) instead of from void loop().
I'm getting the following compiler error:
"invalid use of non-static member function".
If I call ultra[currentSensor].ping_timer(echoCheck) directly from void loop() it gives me no error, so I may be missing something.
Here's the (shortened) piece of code which is generating the error:
#include <NewPing.h>

#define ULTRA_NUM      3
#define MAX_DISTANCE 200

class myclass {
  public:

    void run();
    void echoCheck();

    unsigned int distance[ULTRA_NUM];
    uint8_t currentSensor = 0;
};

NewPing ultra[ULTRA_NUM] = {
  NewPing(4, 5, MAX_DISTANCE),
  NewPing(6, 7, MAX_DISTANCE),
  NewPing(8, 9, MAX_DISTANCE)
};

void myclass::run() {
// ....
      ultra[currentSensor].ping_timer(echoCheck);  // Compiler error
  }

void myclass::echoCheck() {
  if (ultra[currentSensor].check_timer())
    distance[currentSensor] = ultra[currentSensor].ping_result
}

ping_timer() is defined as it follows:
void NewPing::ping_timer(void (*userFunc)(void), unsigned int max_cm_distance) {
    if (max_cm_distance > 0) set_max_distance(max_cm_distance);

    if (!ping_trigger()) return;
    timer_us(ECHO_TIMER_FREQ, userFunc);
}

I hope any of you can help me!
Thanks in advance,
Eduardo

Edit:
What I am trying to do is to adapt this example (from NewPing Arduino Library) so that the sonar ping (sonar[currentSensor].ping_timer(echoCheck)) is done from a class method, and not from void loop().

user4143: The problem is that echo_check isn't void echo_check() but void echo_check(myclass *this) because it's a member function of a class.
You can make the whole thing static (along with run()) by:
class myclass {
    public:
        static void run();
        static void echo_check();
};

static void myclass::run() {
    .... 
}

void myclass::echo_check() {
    ....
}

And then you call:
myclass::run();

instead of instantiating an object.

user75573: Solved:
I moved the event handler out of the class, and made it static void.
Then the code compiled properly
D

23207: <p>I'm having a bad time trying to call a correctly-working expression (<code>ultra[currentSensor].ping_timer(echoCheck)</code>) from an own class method (<code>myclass::run</code>) instead of from <code>void loop()</code>.</p>

<p>I'm getting the following compiler error:
<strong>"invalid use of non-static member function"</strong>.</p>

<p>If I call <code>ultra[currentSensor].ping_timer(echoCheck)</code> directly from <code>void loop()</code> it gives me no error, so I may be missing something.</p>

<p>Here's the (shortened) piece of code which is generating the error:</p>

<pre><code>#include &lt;NewPing.h&gt;

#define ULTRA_NUM      3
#define MAX_DISTANCE 200

class myclass {
  public:

    void run();
    void echoCheck();

    unsigned int distance[ULTRA_NUM];
    uint8_t currentSensor = 0;
};

NewPing ultra[ULTRA_NUM] = {
  NewPing(4, 5, MAX_DISTANCE),
  NewPing(6, 7, MAX_DISTANCE),
  NewPing(8, 9, MAX_DISTANCE)
};

void myclass::run() {
// ....
      ultra[currentSensor].ping_timer(echoCheck);  // Compiler error
  }

void myclass::echoCheck() {
  if (ultra[currentSensor].check_timer())
    distance[currentSensor] = ultra[currentSensor].ping_result
}
</code></pre>

<p><code>ping_timer()</code> is defined as it follows:</p>

<pre><code>void NewPing::ping_timer(void (*userFunc)(void), unsigned int max_cm_distance) {
    if (max_cm_distance &gt; 0) set_max_distance(max_cm_distance);

    if (!ping_trigger()) return;
    timer_us(ECHO_TIMER_FREQ, userFunc);
}
</code></pre>

<p>I hope any of you can help me!</p>

<p>Thanks in advance,</p>

<p>Eduardo</p>

<hr>

<p><strong>Edit</strong>:
What I am trying to do is to adapt <a href="https://bitbucket.org/teckel12/arduino-new-ping/wiki/Help%20with%2015%20Sensors%20Example%20Sketch" rel="nofollow noreferrer">this example</a> (from NewPing Arduino Library) so that the sonar ping (<code>sonar[currentSensor].ping_timer(echoCheck)</code>) is done from a class method, and not from <code>void loop()</code>.</p>
 4143: <p>The problem is that <code>echo_check</code> isn't <code>void echo_check()</code> but <code>void echo_check(myclass *this)</code> because it's a member function of a class.</p>

<p>You can make the whole thing static (along with <code>run()</code>) by:</p>

<pre><code>class myclass {
    public:
        static void run();
        static void echo_check();
};

static void myclass::run() {
    .... 
}

void myclass::echo_check() {
    ....
}
</code></pre>

<p>And then you call:</p>

<pre><code>myclass::run();
</code></pre>

<p>instead of instantiating an object.</p>
 75573: <p>Solved:</p>
<p>I moved the event handler out of the class, and made it static void.</p>
<p>Then the code compiled properly</p>
<p>D</p>
