From f6be9903d07e77d313eef1ee207bb1b8f2c0f44d Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Tue, 21 Jun 2022 22:09:34 +0100 Subject: [PATCH] Support other params --- battery_tester.ino | 79 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 7 deletions(-) diff --git a/battery_tester.ino b/battery_tester.ino index 3f68e50..3b266fd 100644 --- a/battery_tester.ino +++ b/battery_tester.ino @@ -1,4 +1,3 @@ - #include #include @@ -22,10 +21,17 @@ const bool eight[7] = {true, true, true, true, true, true, true}; 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: @@ -66,6 +72,23 @@ void writeDigit(char d, char val) { 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); @@ -73,10 +96,25 @@ void writeDigit(char d, char val) { 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); } @@ -93,6 +131,13 @@ void setup() { 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() { @@ -126,7 +171,27 @@ 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) { -- 2.46.2