Meinst Du sowas?
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB
}
berechnung(5000UL, 161000UL);
berechnung(10UL, 322UL);
}
void loop() {}
void berechnung(unsigned long abstand, unsigned long elapsedtime) {
const double Milli = 1000.0;
const double Micro = 1000000.0;
const double Gewicht = 0.0002; // Gewicht in Kilogramm
const double Multiplikator = 0.5;
const double FPS = 3.2808399; // Umrechnungsfaktor (so genau wie möglich)
double time = (double) elapsedtime / Micro;
double speed = (double) abstand / 100 / time;
double fps = speed * FPS;
double energie = Multiplikator * Gewicht * (speed * speed);
ausgabe(" Abstand:", abstand, " cm");
ausgabe(" Zeit:", elapsedtime, " us");
ausgabe(" Gewicht:", Gewicht * Milli, " g");
ausgabe("Geschwindigkeit:", speed, " m/s");
ausgabe("Geschwindigkeit:", fps, " FPS");
ausgabe(" Energie:", energie, " J");
Serial.println("=====");
}
void ausgabe(const char* text1, double wert, const char* text2) {
Serial.print(text1);
double max = 100000;
for (byte j = 0; j < 6; j++) {
Serial.print(' ');
if (wert >= max) break;
max /= 10;
}
Serial.print(wert);
Serial.println(text2);
}