By Jeff Gray, March 2008

This arduino code averages a analog-in sample in an integer array.

Arduino Code

/* Analog Average - Rolling Buffer
 * Jeff Gray - 2008
 * ------------------ 
 * Averaging Code, modified from Dave Millis example
 */

int average[100];
byte counter = 0;

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

void loop() {
  // read the value from the sensor
  int inAn = analogRead(0);
  average[counter] =  inAn;

  byte c;
  int total = 0;
  for(c = 0;c<100;c++){
    total += average[c];
  }
  int averaged = total / 100;

  Serial.println(averaged);

  counter = (counter + 1) % 100;
}