aboutsummaryrefslogtreecommitdiff
path: root/libraries/detectorBuilding
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/detectorBuilding')
-rw-r--r--libraries/detectorBuilding/src/detectorBuilding.cpp25
-rw-r--r--libraries/detectorBuilding/src/detectorBuilding.h23
2 files changed, 24 insertions, 24 deletions
diff --git a/libraries/detectorBuilding/src/detectorBuilding.cpp b/libraries/detectorBuilding/src/detectorBuilding.cpp
index 7b3fef7..c9367e1 100644
--- a/libraries/detectorBuilding/src/detectorBuilding.cpp
+++ b/libraries/detectorBuilding/src/detectorBuilding.cpp
@@ -8,35 +8,34 @@
#include "Arduino.h"
#include "detectorBuilding.h"
-
// Temperature conversions
-double f2c(double f) { return (f - 32) * 5 / 9; } // Fahrenheit to Celsius
-double c2f(double c) { return c * 9 / 5 + 32; } // Celsius to Fahrenheit
-double k2c(double k) { return k - 273.15; } // Kelvin to Celsius
-double c2k(double c) { return c + 273.15; } // Celsius to Kelvin
-double f2k(double f) { return c2k(f2c(f)); } // Fahrenheit to Kelvin
-double k2f(double k) { return c2f(k2c(k)); } // Kelvin to Fahrenheit
+ld f2c(ld f) { return (f - 32) * 5 / 9; } // Fahrenheit to Celsius
+ld c2f(ld c) { return c * 9 / 5 + 32; } // Celsius to Fahrenheit
+ld k2c(ld k) { return k - 273.15; } // Kelvin to Celsius
+ld c2k(ld c) { return c + 273.15; } // Celsius to Kelvin
+ld f2k(ld f) { return c2k(f2c(f)); } // Fahrenheit to Kelvin
+ld k2f(ld k) { return c2f(k2c(k)); } // Kelvin to Fahrenheit
// Analog to digital conversion
-double a2d(int a) { return V_in * a / analog_max; }
-int d2a(double d) { return d * analog_max / V_in; }
+ld a2d(int a) { return V_in * a / analog_max; }
+int d2a(ld d) { return d * analog_max / V_in; }
// Voltage to resistance conversion
-double v2r(double V_out) { return R_k * (V_in / V_out - 1); }
+ld v2r(ld V_out) { return R_k * (V_in / V_out - 1); }
// Utility functions
// No C++ standard library :(
-void sort(double a[], int n) {
+void sort(ld a[], int n) {
// Bubble sort
// Slow but n < 30 so OK
// Too lazy to implement a fast sort
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - 1; j++) {
if (a[j] > a[j + 1]) {
- double tmp = a[j];
+ ld tmp = a[j];
a[j] = a[j + 1];
a[j + 1] = tmp;
}
@@ -50,7 +49,7 @@ void sort(double a[], int n) {
/*void calculate() {
sort(V, n);
sort(T, n);
- double R[n], L[n], Y[n], G[n];
+ ld 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]);
for (int i = 0; i < n; i++) Y[i] = 1 / c2k(T[i]);
diff --git a/libraries/detectorBuilding/src/detectorBuilding.h b/libraries/detectorBuilding/src/detectorBuilding.h
index 4a268e8..cdb6890 100644
--- a/libraries/detectorBuilding/src/detectorBuilding.h
+++ b/libraries/detectorBuilding/src/detectorBuilding.h
@@ -8,23 +8,24 @@
#define detectorBuilding_h
#include "Arduino.h"
+typedef long double ld;
const int LED_R = 8, LED_G = 10, LED_B = 12, THERM = 0; // Device component pins
-const double R_k = 10000, V_in = 5, analog_max = 1023; // Device constants
+const ld R_k = 10000, V_in = 5, analog_max = 1023; // Device constants
-double f2c(double f);
-double c2f(double c);
-double k2c(double k);
-double c2k(double c);
-double f2k(double f);
-double k2f(double k);
+ld f2c(ld f);
+ld c2f(ld c);
+ld k2c(ld k);
+ld c2k(ld c);
+ld f2k(ld f);
+ld k2f(ld k);
-double a2d(int a);
-int d2a(double d);
+ld a2d(int a);
+int d2a(ld d);
-double v2r(double V_out);
+ld v2r(ld V_out);
-void sort(double a[], int n);
+void sort(ld a[], int n);
//void calculate();