aboutsummaryrefslogtreecommitdiff
path: root/Detector_Building_v2/Detector_Building_v2.ino
diff options
context:
space:
mode:
Diffstat (limited to 'Detector_Building_v2/Detector_Building_v2.ino')
-rw-r--r--Detector_Building_v2/Detector_Building_v2.ino34
1 files changed, 17 insertions, 17 deletions
diff --git a/Detector_Building_v2/Detector_Building_v2.ino b/Detector_Building_v2/Detector_Building_v2.ino
index df54c24..05f148b 100644
--- a/Detector_Building_v2/Detector_Building_v2.ino
+++ b/Detector_Building_v2/Detector_Building_v2.ino
@@ -16,13 +16,13 @@ const bool CALIB = false; // Calibration mode
const int n = 17; // Number of data points
const int m = 1; // Number of segments
const int deg = 2; // Regression degree
-double V[n] = { // Voltage measurements
+ld V[n] = { // Voltage measurements
2.70, 3.39, 2.40, 2.31, 2.19, 1.94, 4.09, 4.11, 3.98, 3.92, 3.77, 3.53, 3.18, 3.07, 2.30, 2.53, 2.49
};
-double T[n] = { // Temperature measurements
+ld T[n] = { // Temperature measurements
24.0, 44.4, 18.4, 13.9, 11.2, 8.6, 60.8, 62.0, 58.3, 53.9, 49.3, 44.9, 41.0, 37.3, 13.4, 19.1, 18.2
};
-double coeff[m][deg + 1];
+ld coeff[m][deg + 1];
void setup() {
@@ -34,14 +34,14 @@ void setup() {
sort(V, n);
sort(T, n);
- double x[n], y[n];
+ ld x[n], y[n];
for (int i = 0; i < n; i++) x[i] = log(v2r(V[i])) - 7;
for (int i = 0; i < n; i++) y[i] = 1000 / c2k(T[i]);
for (int i = 0; i < n; i++) {
Serial.print("(");
- Serial.print(x[i], 12);
+ Serial.print((double)x[i], 12);
Serial.print(", ");
- Serial.print(y[i], 12);
+ Serial.print((double)y[i], 12);
Serial.print(")");
Serial.println();
}
@@ -53,7 +53,7 @@ void setup() {
for (int j = 0; j <= deg; j++){
Serial.print(c++);
Serial.print(": ");
- Serial.print(coeff[i][j], 12);
+ Serial.print((double)coeff[i][j], 12);
Serial.println();
}
}
@@ -63,13 +63,13 @@ void setup() {
void loop() {
int V_raw = analogRead(THERM); // Read in raw analog value
- double V_out = a2d(V_raw);
+ ld V_out = a2d(V_raw);
if (CALIB) {
// Calibration mode
Serial.print("Raw analog reading: ");
Serial.print(V_raw);
Serial.print(" Voltage (V): ");
- Serial.print(V_out);
+ Serial.print((double)V_out);
Serial.println();
delay(500);
return;
@@ -78,15 +78,15 @@ void loop() {
int s = 0;
while (s + 1 < m && V_out < (V[s * n / m - 1] + V[s * n / m]) / 2) s++; // Find correct segment
- double logR = log(v2r(V_out)) - 7;
- double sum = 0, prod = 1;
+ ld logR = log(v2r(V_out)) - 7;
+ ld sum = 0, prod = 1;
for (int i = 0; i <= deg; i++) {
sum += coeff[s][deg - i] * prod;
prod *= logR;
}
- double K = 1000 / sum;
- double C = k2c(K);
- double F = c2f(C);
+ ld K = 1000 / sum;
+ ld C = k2c(K);
+ ld F = c2f(C);
// LED stuff
@@ -114,11 +114,11 @@ void loop() {
// Output voltage, temperature
Serial.print("Raw analog reading: ");
- Serial.print(V_raw);
+ Serial.print((double)V_raw);
Serial.print(" Voltage (V): ");
- Serial.print(V_out);
+ Serial.print((double)V_out);
Serial.print(" Temperature (°C): ");
- Serial.print(C);
+ Serial.print((double)C);
// For reference
/*Serial.print(" Temperature (°F): ");
Serial.print(F);