-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrend.cpp
More file actions
59 lines (46 loc) · 751 Bytes
/
trend.cpp
File metadata and controls
59 lines (46 loc) · 751 Bytes
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 "trend.h"
#include <math.h>
char Trend::get(uint16_t current)
{
trend[end++] = current;
if (end == 6) {
end = 0;
}
//Serial.print("end: ");
//Serial.println(end);
short sum1 = trend[end];
short sum2 = 0;
//Serial.print("start = ");
//Serial.println(trend[end]);
uint8_t i = end + 1;
if (i == 6) {
i = 0;
}
uint8_t count = 1;
while (i != end) {
//Serial.print("i = ");
//Serial.println(i);
//Serial.println(trend[i]);
if (count++ < 3) {
sum1 += trend[i];
}
else {
sum2 += trend[i];
}
++i;
if (i == 6) {
i = 0;
}
}
sum1 /= 3;
sum2 /= 3;
//Serial.println(sum1);
//Serial.println(sum2);
if (abs(sum1 - sum2) < 50) {
return 0;
}
if (sum2 > sum1) {
return 1;
}
return -1;
}