Skip to content

Commit 5749b87

Browse files
committed
add array example
1 parent b53b1ea commit 5749b87

8 files changed

Lines changed: 106 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.4.8] - 2025-08-01
10+
- add array example
11+
- update examples
12+
- minor edits
13+
914
## [0.4.7] - 2024-08-12
1015
- Fix #33, add **float getCoefficientOfVariation()**
1116
- update readme.md

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2012-2024 Rob Tillaart
3+
Copyright (c) 2012-2025 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,18 @@ update the internal **\_sum**.
3636
- https://github.com/RobTillaart/Correlation
3737
- https://github.com/RobTillaart/GST - Golden standard test metrics
3838
- https://github.com/RobTillaart/Histogram
39+
- https://github.com/RobTillaart/infiniteAverage
3940
- https://github.com/RobTillaart/RunningAngle
4041
- https://github.com/RobTillaart/RunningAverage
4142
- https://github.com/RobTillaart/RunningMedian
4243
- https://github.com/RobTillaart/statHelpers - combinations & permutations
4344
- https://github.com/RobTillaart/Statistic
4445
- https://github.com/RobTillaart/Student
4546

47+
For printing floats in scientific or engineering format
48+
49+
https://github.com/RobTillaart/printHelpers
50+
4651

4752
## Interface
4853

RunningAverage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: RunningAverage.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.4.7
4+
// VERSION: 0.4.8
55
// DATE: 2011-01-30
66
// PURPOSE: Arduino library to calculate the running average by means of a circular buffer
77
// URL: https://github.com/RobTillaart/RunningAverage

RunningAverage.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: RunningAverage.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.4.7
5+
// VERSION: 0.4.8
66
// DATE: 2011-01-30
77
// PURPOSE: Arduino library to calculate the running average by means of a circular buffer
88
// URL: https://github.com/RobTillaart/RunningAverage
@@ -14,7 +14,7 @@
1414
#include "Arduino.h"
1515

1616

17-
#define RUNNINGAVERAGE_LIB_VERSION (F("0.4.7"))
17+
#define RUNNINGAVERAGE_LIB_VERSION (F("0.4.8"))
1818

1919

2020
class RunningAverage

examples/ra_array/ra_array.ino

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//
2+
// FILE: ra_array.ino
3+
// AUTHOR: Rob Tillaart
4+
// PURPOSE: show working of an array of runningAverage objects
5+
// URL: https://github.com/RobTillaart/RunningAverage
6+
7+
8+
#include "RunningAverage.h"
9+
10+
// note the differrent sizes.
11+
//RunningAverage RA0(10);
12+
//RunningAverage RA1(15);
13+
//RunningAverage RA2(20);
14+
//RunningAverage RA3(10);
15+
//RunningAverage RA4(15);
16+
//RunningAverage RA5(20);
17+
//
18+
//RunningAverage RA[6] = { RA0, RA1, RA2, RA3, RA4, RA5 };
19+
20+
RunningAverage RA[6] =
21+
{
22+
RunningAverage(5),
23+
RunningAverage(7),
24+
RunningAverage(9),
25+
RunningAverage(11),
26+
RunningAverage(13),
27+
RunningAverage(15),
28+
};
29+
30+
uint32_t samples = 0;
31+
32+
33+
void setup(void)
34+
{
35+
Serial.begin(115200);
36+
Serial.println();
37+
Serial.println(__FILE__);
38+
Serial.print("RUNNINGAVERAGE_LIB_VERSION: ");
39+
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
40+
Serial.println();
41+
42+
// explicitly start clean
43+
for (int i = 0; i < 6; i++)
44+
{
45+
RA[i].clear();
46+
}
47+
48+
// check different sizes.
49+
for (int i = 0; i < 6; i++)
50+
{
51+
Serial.print('\t');
52+
Serial.print(RA[i].getSize());
53+
}
54+
Serial.println();
55+
}
56+
57+
58+
void loop(void)
59+
{
60+
// read 6 ADC's
61+
for (int i = 0; i < 6; i++)
62+
{
63+
int value = analogRead(A0 + i);
64+
// optional conversion here
65+
RA[i].addValue(value);
66+
//Serial.print(value);
67+
//Serial.print("\t");
68+
}
69+
//Serial.println();
70+
71+
// print a separator every 20 lines
72+
if (samples % 20 == 0)
73+
{
74+
Serial.println("\n");
75+
}
76+
samples++;
77+
78+
Serial.print(samples);
79+
for (int i = 0; i < 6; i++)
80+
{
81+
Serial.print('\t');
82+
Serial.print(RA[i].getAverage(), 2);
83+
}
84+
Serial.println();
85+
86+
delay(50);
87+
}
88+
89+
90+
// -- END OF FILE --

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/RunningAverage.git"
1717
},
18-
"version": "0.4.7",
18+
"version": "0.4.8",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=RunningAverage
2-
version=0.4.7
2+
version=0.4.8
33
author=Rob Tillaart <rob.tillaart@gmail.com>
44
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
55
sentence=The library stores the last N individual values in a circular buffer to calculate the running average.

0 commit comments

Comments
 (0)