Or use an array of objects. Note the allocation is somewhat different
(note not tested, highly experimental)
//
// FILE: runningAverageTest.ino
// AUTHOR: Rob Tillaart
// DATE: 2014-05-07
//
// PUPROSE: show working of runningAverage
//
#include "RunningAverage.h"
RunningAverage *RA[6]; // 6 pointers to RA objects
int pin[6] = {
A0, A1, A2, A3, A4, A5 };
int size[6] = { 15, 13, 11, 9, 7, 5 };
int samples = 0;
void setup(void)
{
Serial.begin(115200);
Serial.println("Demo RunningAverage lib");
Serial.print("Version: ");
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
for (int i=0;i<6; i++)
{
RA[i] = new RunningAverage( size[i] );
RA[i]->clear();
}
}
void loop(void)
{
for (int i=0; i<6; i++)
{
RA[i]->addValue(analogRead(pin[i]));
}
for (int i=0; i<6; i++)
{
Serial.print(RA[i]->getAverage(), 3);
Serial.print(",");
}
Serial.println();
samples++;
if (samples == 300)
{
samples = 0;
for (int i=0;i<6; i++)
{
RA[i]->clear();
}
}
delay(100);
}