Browse Source

Fehlerbehebung und File_write ergänzt

master
Julian Graf 2 years ago
parent
commit
43245b521a
1 changed files with 50 additions and 23 deletions
  1. 50
    23
      Teensy4.1_Datalogger new.ino

+ 50
- 23
Teensy4.1_Datalogger new.ino View File

@@ -87,10 +87,14 @@ public:
summ = summ + pow((speed_per_second[i] - arithmetic_mean), 2);
square_summ = square_summ + pow((speed_per_second[i] - square_mean), 2);
cubic_summ = cubic_summ + pow((speed_per_second[i] - cubic_mean), 2);
speed_min = min(speed_min, speed_per_second[i]);
speed_max = max(speed_max, speed_per_second[i]);
}
arithmetic_deviation = pow((summ / float(amount_saved - 1)), (1 / 2.0));
square_deviation = pow((square_summ / float(amount_saved - 1)), (1 / 2.0));
cubic_deviation = pow((cubic_summ / float(amount_saved - 1)), (1 / 2.0));

seconds_skipped = 60 - amount_saved;
}
float arithmetic_mean;
@@ -101,14 +105,20 @@ public:
float cubic_mean;
float cubic_deviation;

float speed_min;
float speed_max;

int seconds_skipped;
};


struct anemomenter_maessurement {
public:
int pin = 0;
int seconds_saved = 0;
int minutes_saved = 0;

void setup(int pin) {
this->reed_contact = Bounce(pin, 10);
}

void meassure() {
if (reed_contact.update() && reed_contact.fallingEdge()) {
@@ -117,20 +127,30 @@ public:
}
void save_wind_speed() {
wind_speed_per_second[seconds_saved] = 0.4 * count_per_second;
seconds_saved++;
wind_speed_per_second[saved_seconds] = 0.4 * count_per_second;
saved_seconds++;
}

void calculate() {
values[minutes_saved].calculate(wind_speed_per_second, seconds_saved);
seconds_saved = 0;
minutes_saved++;
values[saved_minutes].calculate(wind_speed_per_second, saved_seconds);
saved_seconds = 0;
saved_minutes++;
}

void print() {
void file_print() {

}
for (int i = 0; i < saved_minutes; i++) {
file.printf("Min: %f,\tMax: %f,\t", values[i].speed_min, values[i].speed_max);
file.printf("Arith. Mittel: % f,\tStandard Abw.: %f\t", values[i].arithmetic_mean, values[i].arithmetic_deviation);
file.printf("Quadr. Mittel: % f,\tStandard Abw.: %f\t", values[i].square_mean, values[i].square_deviation);
file.printf("Kub. Mittel: %f,\tStandard Abw.: %f\t", values[i].cubic_mean, values[i].cubic_deviation);
file.printf("Übersprungene Sek.: %i\n", values[i].seconds_skipped);
}
file.printf("Übersprungene Min.: %i\n", 60 - saved_minutes);

saved_minutes = 0;
}
private:
int count_per_second = 0;
@@ -138,10 +158,9 @@ private:
int saved_minutes = 0;
float wind_speed_per_second[60];

calculations values[60];

Bounce reed_contact;

Bounce reed_contact = Bounce(pin, 10);
calculations values[60];

}anemometer_1, anemometer_2, anemometer_3;

@@ -178,11 +197,19 @@ void write_sd() {

file.println("Messdaten von Windmessmasst");
file.println();
file.println("Data logger : Teensy 4.2");
file.println("Data logger : Teensy 4.1");
file.println(software_name);
file.println();
file.println("");

file.println("Anemometer_1 Werte:");
anemometer_1.file_print();
file.println("Anemometer_2 Werte:");
anemometer_2.file_print();
file.println("Anemometer_3 Werte:");
anemometer_3.file_print();

file.close();
Serial.println("Ende des Schreibvorgangs");
}
}
@@ -205,6 +232,7 @@ void every_minute() {

void every_hour() {

write_sd();
last_hour = hour();
}

@@ -238,9 +266,9 @@ void setup()
sd.initErrorHalt(&Serial);
}
anemometer_1.pin = 2;
anemometer_2.pin = 9;
anemometer_3.pin = 22;
anemometer_1.setup(2);
anemometer_2.setup(9);
anemometer_3.setup(22);


Serial.println("Messung startet");
@@ -260,13 +288,12 @@ void loop()
anemometer_3.meassure();

if (second() != last_second) {
every_second();
if (minute() != last_minute) {
every_minute();
if (hour() != last_hour) {
every_hour();
}
every_minute();
}
every_second();
}
}

}

Loading…
Cancel
Save