Arduino Sensör Veri İşleme – RunningAverage

RunningAverage library

A small sketch shows how it can be used. A random generator is used to mimic a sensor.

//    FILE: runningAverageTest.pde
//  AUTHOR: Rob Tillaart
//    DATE: 2012-12-30
// PUPROSE: show working of runningAverage

#include "RunningAverage.h"

RunningAverage myRA(10);
int samples = 0;

void setup(void) 
  Serial.println("Demo RunningAverage lib");
  Serial.print("Version: ");
  myRA.clear(); // explicitly start clean

void loop(void) 
  long rn = random(0, 1000);
  myRA.addValue(rn * 0.001);
  Serial.print("Running Average: ");
  Serial.println(myRA.getAverage(), 3);

  if (samples == 300)
    samples = 0;

setup() the myRA is cleared so we can start adding new data.

In loop() first a random number is generated and converted to a float to be added to myRA. Then the runningAverage is printed to the serial port. One could also display it on some LCD or send over ethernet etc. When 300 items are added myRA is cleared to start over again


SD KART MODÜLÜ,PR-15543.html.

Leave a Reply