]> git.friedersdorff.com Git - max/battery_tester.git/commitdiff
Fix bug
authorMaximilian Friedersdorff <max@friedersdorff.com>
Tue, 21 Jun 2022 14:02:25 +0000 (15:02 +0100)
committerMaximilian Friedersdorff <max@friedersdorff.com>
Tue, 21 Jun 2022 14:02:25 +0000 (15:02 +0100)
battery_tester.ino

index 913d434585e0f37b4a098cc648196ac6c28e00b9..3f68e50f992da1960822e2c9774ce6fb7e1eec49 100644 (file)
@@ -1,3 +1,4 @@
+
 #include <LightChrono.h>
 #include <Chrono.h>
 
@@ -104,17 +105,17 @@ void loop() {
     float mwatthours;
 
     if (timer.hasPassed(1000)) {
+        unsigned long passed = timer.elapsed();
         timer.restart();
+        battery_voltage = readVoltage(A0);
+
         if (battery_voltage < 0.8) {
             delay(200);
         } else {
-            unsigned long passed = timer.elapsed();
-            
 
             shunt_voltage = readVoltage(A1);
             shunt_current = shunt_voltage/APPARENT_SHUNT_RESISTANCE;
 
-            battery_voltage = readVoltage(A0);
 
             amps_in_period = shunt_current * passed/1000;
             watts_in_period = amps_in_period * battery_voltage;