-
#include <LightChrono.h>
#include <Chrono.h>
const bool nine[7] = {true, true, true, true, false, true, true};
const bool zero[7] = {true, true, true, true, true, true, false};
+const bool U[7] = {false, true, true, true, true, true, false};
+const bool I[7] = {false, false, true, false, false, false, false};
+const bool P[7] = {true, true, false, false, true, true, true};
+
+unsigned char display_state = 0;
+
Chrono timer;
+Chrono debounce;
-void writeDigit(char d, char val) {
+void writeDigit(char d, char val, bool dec) {
const bool *segs;
switch (val) {
case 0:
digitalWrite(segments[i], LOW);
}
}
+ if (dec) {
+ digitalWrite(15, HIGH);
+ }
+ digitalWrite(digits[d], LOW);
+ delay(1);
+ digitalWrite(digits[d], HIGH);
+ digitalWrite(15, LOW);
+}
+
+void writeLetter(char d, const bool val[]) {
+ for (int i = 0; i < 7; ++i) {
+ if (val[i]) {
+ digitalWrite(segments[i], HIGH);
+ } else {
+ digitalWrite(segments[i], LOW);
+ }
+ }
digitalWrite(digits[d], LOW);
delay(1);
digitalWrite(digits[d], HIGH);
void showNumber(float number) {
int n = number;
- writeDigit(0, (n/1000U) % 10);
- writeDigit(1, (n/100U) % 10);
- writeDigit(2, (n/10U) % 10);
- writeDigit(3, n % 10);
+ writeDigit(0, (n/1000U) % 10, false);
+ writeDigit(1, (n/100U) % 10, false);
+ writeDigit(2, (n/10U) % 10, false);
+ writeDigit(3, n % 10, false);
+}
+
+void showVoltage(float volts) {
+ int cvolts = volts * 100;
+ writeDigit(0, (cvolts/100U) % 10, true);
+ writeDigit(1, (cvolts/10U) % 10, false);
+ writeDigit(2, cvolts % 10, false);
+ writeLetter(3, U);
+}
+void showCurrent(float current) {
+ int camp = current * 100;
+ writeDigit(0, (camp/100U) % 10, true);
+ writeDigit(1, (camp/10U) % 10, false);
+ writeDigit(2, camp % 10, false);
+ writeLetter(3, I);
}
pinMode(segments[i], OUTPUT);
digitalWrite(segments[i], LOW);
}
+
+ pinMode(15, OUTPUT);
+ digitalWrite(15, LOW);
+
+ pinMode(19, INPUT);
+ pinMode(20, INPUT);
+ pinMode(21, INPUT);
}
void loop() {
mwatthours = wattseconds/3.6;
}
}
- showNumber(mamphours);
+ if (debounce.hasPassed(300) && !digitalRead(19)) {
+ display_state = (display_state + 1) % 4;
+ Serial.println(display_state);
+ debounce.restart();
+ } else {
+ switch (display_state) {
+ case 0:
+ showNumber(mamphours);
+ break;
+ case 1:
+ showVoltage(battery_voltage);
+ break;
+ case 2:
+ showCurrent(shunt_current);
+ break;
+ case 3:
+ showNumber(mwatthours);
+ writeLetter(3, P);
+ break;
+ }
+ }
}
float readVoltage(int pin) {