Code Help: I cannot get data average to compile and run

Hi I am trying to work with this code to learn more but cannot get it to compile and run on UNO R3 board. I have put AverageList into the Library folder but no worky.

#include <AverageList.h>

const byte LIST_SIZE = 20;

void setup() {

  //enable user feedback
  Serial.begin(9600);

  //this is used for storage, an array of ints
  int arr[LIST_SIZE] = {0};

  //initialize an AverageList object that operates on ints
  AverageList<int> testList(arr, LIST_SIZE);

  //take samples
  for (int i = 0; i < LIST_SIZE; i++) {
    testList = analogRead(2);
    delay(20);
  }

  Serial.println( testList.getTotalAverage());
}

I have put AverageList into the Library folder but no worky.

Until you tell us what the problem is, no helpy.

You need to have a loop() function, even if it is empty.

If you got the file from the Playground, it is a version written for an older IDE. You need to replace the #include<WProgram.h> with #include<Arduino.h> in the AverageList.h file in the libraries folder.

The indexer is missing for the array in the for loop. It should be:

for (int i = 0; i < LIST_SIZE; i++) {
    testList[i] = analogRead(2);

In the future, please include the error messages in your post and/or describe the issue(s) that you have. Makes to easier for us to help.

  //take samples
  for (int i = 0; i < LIST_SIZE; i++) {
    testList = analogRead(2);
    delay(20);
  }

So read the analogue input 20 times overwriteing the testList variable every time, when the loop is finished find the avrage of an array that doesn’t exist.

Put each reading in a different place in your list you defined as arr and then find the avrage of that.

Mind you it is such a stupid library to use, why not just calculate the sum total as you read each sample and then divide that by the number of samples. Why use a library for that?