aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTa180m2020-01-13 12:25:14 -0600
committerGitHub2020-01-13 12:25:14 -0600
commit74365eae17d5f411a5ac2ec2f2897def456944ad (patch)
tree6203d58682216862a58c234f5dcac0738ec3849d
parentf24c4a10c834ba4ce4caf8b610e73f3f016fb6cf (diff)
Update Detector_Building_v2.ino
-rw-r--r--Detector_Building_v2.ino24
1 files changed, 21 insertions, 3 deletions
diff --git a/Detector_Building_v2.ino b/Detector_Building_v2.ino
index 15dc90c..da46a36 100644
--- a/Detector_Building_v2.ino
+++ b/Detector_Building_v2.ino
@@ -25,17 +25,35 @@ inline double f2k(double f) { return c2k(f2c(f)); } // Fahrenheit to Kelvin
inline double k2f(double k) { return c2f(k2c(k)); } // Kelvin to Fahrenheit
+// Utility functions
+// No C++ standard library :(
+void sort(int& a[], int n) {
+ // Bubble sort
+ // Slow but n < 30 so OK
+ for (int i = 0; i < n; i++) {
+ for (int j = 0; j < n - 1; j++) {
+ if (a[j] > a[j + 1]) {
+ int tmp = a[j];
+ a[j] = a[j + 1];
+ a[j + 1] = tmp;
+ }
+ }
+ }
+}
+
+
// Calibration data
-// MUST be sorted or you will get garbage results
const int n = 3, m = n / 3; // Number of data points, MUST be multiple of 3
-const double V[n] = { 2.5, 3.26, 3.96 }; // Voltage measurements
-const double T[n] = { 25, 39.15, 60 }; // Temperature measurements
+double V[n] = { 2.5, 3.26, 3.96 }; // Voltage measurements
+double T[n] = { 25, 39.15, 60 }; // Temperature measurements
double V_mid[m]; // Stores each piecewise segment for binary search
double A[m], B[m], C[m]; // Coeficients for each piecewise component
// Calculations
void calculate() {
+ sort(V, n);
+ sort(T, n);
double R[n], L[n], Y[n], G[n];
for (int i = 0; i < n; i++) R[i] = R_k * (V_in / V[i] - 1);
for (int i = 0; i < n; i++) L[i] = log(R[i]);