Using Average.h

Hi all,

Long time lurker here, but unfortunately my first post had to be a question :confused:

I see that questions about Average.h has been asked a few times, but I couldn't find any solution to it, so I hope we can get somewhere with this thread.

For some odd reason, Average.h does not work as shown in the examples. Yes, the demo sketch in the library compiles, but I can't see a proper way to implement that method. The example provided on this site does not compile at all:

error: 'mean' was not declared in this scope

   Serial.print(mean(d,CNT),DEC);

and so on for all methods.

What I try to do, is getting a maximum and minimum value from an array of floats, like this:

#include <Average.h>

float tester[] = {10.23, 43.87, 14.98, 0.27}; // Array of 4 values as an example
int aLength = 4;  // 4 values in the array

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(maximum(tester, aLength));
  Serial.println(minimum(tester, aLength));
}

Of course, this fails in the samme manner as "maximum" and "minimum" is not declared, but shouldn't it already be declared in Average.h?

If the library was updated and that example is no longer valid; how would you be able to do this then? I see that the library-provided example has this line:

Average<float> ave(10);

I think this suggests that the array must be declared by Average.h, but that doesn't work either.

I'm at a loss here, so I hope anyone can help me out. I might have to make my own routine to find min and max values if Average.h doesn't work.

Thanks in advance :slight_smile:

What is this "Average.h" you speak of? :slight_smile: I can't find it anywhere. Where did you get it?

Ooops, sorry - I forgot to paste in the link :frowning:

http://playground.arduino.cc/Main/Average

It's a templated class. You failed to make tester[] an Average type, as it was in the example sketch.

I tried that in my main project, but that won't work with my existing array.
Made a new sketch using the newer example, and it seems to work, but it's a clumsy way of doing it (in my opinion). My best solution to this is having two parallel arrays just so I can use that function to get max and min. Seems like a better idea than having to adapt 2500+ lines of code to work :slight_smile:

#include <Average.h>

Average<float> tester(4);

void setup() {
    Serial.begin(9600);
}

void loop() {
    tester.push(0.23); // Filling in some random data
    tester.push(0.37);
    tester.push(26.91);
    tester.push(42.85);

    Serial.print(tester.maximum());
    Serial.print("\t\t");
    Serial.println(tester.minimum());
    delay(1000);
}