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

summ = summ + pow((speed_per_second[i] - arithmetic_mean), 2); summ = summ + pow((speed_per_second[i] - arithmetic_mean), 2);
square_summ = square_summ + pow((speed_per_second[i] - square_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); 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)); arithmetic_deviation = pow((summ / float(amount_saved - 1)), (1 / 2.0));
square_deviation = pow((square_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)); cubic_deviation = pow((cubic_summ / float(amount_saved - 1)), (1 / 2.0));

seconds_skipped = 60 - amount_saved;
} }
float arithmetic_mean; float arithmetic_mean;
float cubic_mean; float cubic_mean;
float cubic_deviation; float cubic_deviation;

float speed_min;
float speed_max;

int seconds_skipped;
}; };




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

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


void meassure() { void meassure() {
if (reed_contact.update() && reed_contact.fallingEdge()) { if (reed_contact.update() && reed_contact.fallingEdge()) {
} }
void save_wind_speed() { 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() { 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: private:
int count_per_second = 0; int count_per_second = 0;
int saved_minutes = 0; int saved_minutes = 0;
float wind_speed_per_second[60]; 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; }anemometer_1, anemometer_2, anemometer_3;




file.println("Messdaten von Windmessmasst"); file.println("Messdaten von Windmessmasst");
file.println(); file.println();
file.println("Data logger : Teensy 4.2");
file.println("Data logger : Teensy 4.1");
file.println(software_name); file.println(software_name);
file.println(); 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");
} }
} }


void every_hour() { void every_hour() {


write_sd();
last_hour = hour(); last_hour = hour();
} }


sd.initErrorHalt(&Serial); 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"); Serial.println("Messung startet");
anemometer_3.meassure(); anemometer_3.meassure();


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

} }

Loading…
Cancel
Save