Chrono timer;
Chrono debounce;
+Chrono blank_timer;
+
+float shunt_voltage = 0;
+float shunt_current = 0;
+float battery_voltage = 0;
+float amps_in_period = 0;
+float watts_in_period = 0;
+float mamphours = 0;
+float mwatthours = 0;
void writeDigit(char d, char val, bool dec) {
}
}
if (dec) {
- digitalWrite(15, HIGH);
+ digitalWrite(segments[7], HIGH);
}
digitalWrite(digits[d], LOW);
delay(1);
digitalWrite(digits[d], HIGH);
- digitalWrite(15, LOW);
+ digitalWrite(segments[7], LOW);
}
void writeLetter(char d, const bool val[]) {
writeLetter(3, I);
}
+void showWh(float watthours) {
+ int w = watthours;
+ writeDigit(0, (w/1000U) % 10, true);
+ writeDigit(1, (w/100U) % 10, false);
+ writeDigit(2, (w/10U) % 10, false);
+ writeLetter(3, P);
+}
+
void setup() {
// put your setup code here, to run once:
}
void loop() {
- 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();
battery_voltage = readVoltage(A0);
if (battery_voltage < 0.8) {
- delay(200);
+ blank_timer.restart();
} else {
-
shunt_voltage = readVoltage(A1);
shunt_current = shunt_voltage/APPARENT_SHUNT_RESISTANCE;
}
if (debounce.hasPassed(300) && !digitalRead(19)) {
display_state = (display_state + 1) % 4;
- Serial.println(display_state);
debounce.restart();
- } else {
+ } else if (blank_timer.hasPassed(200)) {
switch (display_state) {
case 0:
showNumber(mamphours);
showCurrent(shunt_current);
break;
case 3:
- showNumber(mwatthours);
- writeLetter(3, P);
+ showWh(mwatthours);
break;
}
}