aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTa180m2020-03-05 15:44:00 -0600
committerTa180m2020-03-05 15:44:00 -0600
commit2ec448283444d3cdda693e2e1784cc02b170581c (patch)
tree1782b834670f1c021845beaf7c505e873868afcb
parentdf61ee825fb67df6a1151339c53f4f8b04f756cb (diff)
Updated some stuff
-rw-r--r--Detector_Building_v2/Detector_Building_v2.ino30
-rw-r--r--libraries/detectorBuilding/src/detectorBuilding.cpp2
2 files changed, 18 insertions, 14 deletions
diff --git a/Detector_Building_v2/Detector_Building_v2.ino b/Detector_Building_v2/Detector_Building_v2.ino
index 05f148b..b63f792 100644
--- a/Detector_Building_v2/Detector_Building_v2.ino
+++ b/Detector_Building_v2/Detector_Building_v2.ino
@@ -15,14 +15,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
-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
-};
-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
+const int deg = 3; // Regression degree
+ld data[2 * n] = {
+// V T
+ 2.70, 24.0
+
};
-ld coeff[m][deg + 1];
+ld coeff[m][deg + 1], V[n], T[n];
void setup() {
@@ -31,23 +30,28 @@ void setup() {
pinMode(LED_G, OUTPUT);
pinMode(LED_B, OUTPUT);
+ for (int i = 0; i < n; i++) {
+ V[i] = data[2 * i];
+ T[i] = data[2 * i + 1];
+ }
+
sort(V, n);
sort(T, 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("(");
+ /*for (int i = 0; i < n; i++) {
+ Serial.print("{");
Serial.print((double)x[i], 12);
Serial.print(", ");
Serial.print((double)y[i], 12);
- Serial.print(")");
+ Serial.print("},");
Serial.println();
- }
+ }*/
for (int i = 0; i < m; i++) {
int ret = fitCurve(deg, n / m, x + i * n / m, y + i * n / m, deg + 1, coeff[i]);
- if (ret == 0){ //Returned value is 0 if no error
+ /*if (ret == 0) { // Returned value is 0 if no error
char c = 'A';
Serial.println("Coefficients are:");
for (int j = 0; j <= deg; j++){
@@ -56,7 +60,7 @@ void setup() {
Serial.print((double)coeff[i][j], 12);
Serial.println();
}
- }
+ }*/
}
}
diff --git a/libraries/detectorBuilding/src/detectorBuilding.cpp b/libraries/detectorBuilding/src/detectorBuilding.cpp
index c9367e1..0c31c28 100644
--- a/libraries/detectorBuilding/src/detectorBuilding.cpp
+++ b/libraries/detectorBuilding/src/detectorBuilding.cpp
@@ -34,7 +34,7 @@ void sort(ld a[], int n) {
// 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]) {
+ if (a[j] < a[j + 1]) {
ld tmp = a[j];
a[j] = a[j + 1];
a[j + 1] = tmp;