-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_test.cpp
59 lines (49 loc) · 1.38 KB
/
build_test.cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Include lib:
#include <Arduino.h>
#include <DataTome.h>
// Create an Arithmetic Moving Average object of unsigned int type,
// 10 in size
DataTomeMvAvg<int, long int> test(10);
DataTomeAnalysis<int, long int> test2(10);
DataTomeCumulative<double> test3;
DataTomeExpAvg<double> test4;
// This variable just generates input for average test
int delta_x = 0;
void setup() {
// Initialize serial interface
Serial.begin(9600);
}
void loop() {
// Pushes the input in the moving average object
test.push(delta_x);
test2.push(delta_x);
test3.push(delta_x);
test4.push(delta_x);
// Generates the next input
delta_x += 3;
if (delta_x > 1000) delta_x = 0;
// Prints each value stored in the moving average
for (uint8_t i = 0; i < test.size(); i++) {
Serial.print(test[i]);
Serial.print(" ");
}
// Prints the result of the average
Serial.print("= ");
Serial.print(test.get());
// Prints the value stored in the first and last indexes
Serial.print(" | f: ");
Serial.print(test.front());
Serial.print(" b: ");
Serial.println(test.back());
Serial.print("Analysis: ");
Serial.print(test2.mean());
Serial.print(" | Std: ");
Serial.print(test2.std());
Serial.print(" | Median: ");
Serial.println(test2.median());
Serial.print("Cumulative: ");
Serial.println(test3.get());
Serial.print(" | ExpAvg: ");
Serial.println(test4.get());
delay(1000);
}