- float shunt_voltage;
- float shunt_current;
- float battery_voltage;
- float amps_in_period;
- float watts_in_period;
- float mamphours;
- float mwatthours;
-
- if (timer.hasPassed(1000)) {
- unsigned long passed = timer.elapsed();
- timer.restart();
-
- 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;
-
- ampseconds += amps_in_period;
- wattseconds += watts_in_period;
- mamphours = ampseconds/3.6;
- mwatthours = wattseconds/3.6;
-
- if (battery_voltage < 0.8) {
- delay(200);
+ float shunt_voltage;
+ float shunt_current;
+ float battery_voltage;
+ float amps_in_period;
+ float watts_in_period;
+ float mamphours;
+ float mwatthours;
+
+ if (timer.hasPassed(1000)) {
+ timer.restart();
+ 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;
+
+ ampseconds += amps_in_period;
+ wattseconds += watts_in_period;
+ mamphours = ampseconds/3.6;
+ mwatthours = wattseconds/3.6;
+ }