aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2022-02-11 12:08:58 -0600
committerAnthony Wang2022-02-11 12:08:58 -0600
commitaeb07c9c25811c4b9cb9725a524d82819d694248 (patch)
tree72520baf6f12846064d38e01988630f20c35346f
parent257e0247c614600865d861a0b818f39146a89744 (diff)
Use arduinoCurveFitting for regression
-rw-r--r--main.ino13
1 files changed, 11 insertions, 2 deletions
diff --git a/main.ino b/main.ino
index b59d7b2..694f8a3 100644
--- a/main.ino
+++ b/main.ino
@@ -15,6 +15,9 @@ Licensed under the Parity Public License
*/
+#include <curveFitting.h>
+
+
using ld = long double;
@@ -31,6 +34,9 @@ ld v2r(ld V_out) { return R_k * (V_in / V_out - 1); }
ld vol[100];
int con[100];
+const int order = 2;
+int coeff[order + 1];
+
void setup() {
Serial.begin(9600);
Serial.println("Starting calibration")
@@ -49,9 +55,12 @@ void setup() {
++n;
}
-
+ fitCurve(order, n, vol, con, coeff);
}
void loop() {
-
+ v = a2d(analogRead(THERM));
+ c = 0;
+ for (int i = n; i >= 0; --i) c = v*c + coeff[i];
+ Serial.println(c);
}