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.

Arduino

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

<em>//

// FILE: runningAverageTest.pde

// AUTHOR: Rob Tillaart

// DATE: 2012-12-30

//

// PUPROSE: show working of runningAverage

//

#include "RunningAverage.h"

RunningAveragemyRA(10);

intsamples=0;

voidsetup(void)

{

Serial.begin(115200);

Serial.println("Demo RunningAverage lib");

Serial.print("Version: ");

Serial.println(RUNNINGAVERAGE_LIB_VERSION);

myRA.clear();// explicitly start clean

}

voidloop(void)

{

longrn=random(0,1000);

myRA.addValue(rn*0.001);

samples++;

Serial.print("Running Average: ");

Serial.println(myRA.getAverage(),3);

if(samples==300)

{

samples=0;

myRA.clear();

}

delay(100);

}</em>

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