You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
smoothReading = new T[smoothReadingsFactor]; // Create the actual array of the required size
54
+
55
+
// Initialise all the values in the array to zero
56
+
for (int thisReading = 0; thisReading < smoothReadingsNum; thisReading++) {
57
+
smoothReading[thisReading] = 0;
58
+
}
59
+
60
+
returntrue;
61
+
break;
62
+
63
+
case SMOOTHED_EXPONENTIAL : // SMOOTHED_EXPONENTIAL
64
+
65
+
smoothReading = new T[2];
66
+
smoothReading[0] = 0;
67
+
smoothReading[1] = 0; // Second value in array used for storing last value added
68
+
69
+
returntrue;
70
+
break;
71
+
72
+
default :
73
+
returnfalse;
74
+
break;
75
+
}
76
+
77
+
}
78
+
79
+
// Add a value to the array
80
+
template <typename T>
81
+
bool Smoothed<T>::add (T newReading) {
82
+
switch (smoothMode) {
83
+
case SMOOTHED_AVERAGE : // SMOOTHED_AVERAGE
84
+
85
+
if(smoothReadingsNum < smoothReadingsFactor) { smoothReadingsNum++; } // Keep record of the number of readings being averaged. This will count up to the arrany saize then stay at that number
86
+
87
+
smoothReading[smoothReadingsPosition] = newReading; // Add the new value
88
+
89
+
if (smoothReadingsPosition == (smoothReadingsFactor - 1)) { // If at the end of the array
90
+
smoothReadingsPosition = 0; // Increment to the beginning of the array
91
+
} else {
92
+
smoothReadingsPosition++; // Increment to next array position position
93
+
}
94
+
95
+
returntrue;
96
+
break;
97
+
98
+
case SMOOTHED_EXPONENTIAL : // SMOOTHED_EXPONENTIAL
0 commit comments