From 014fb1b6e837fed9ded2696d1ab14dc22923af0d Mon Sep 17 00:00:00 2001 From: Markus Knapp Date: Tue, 5 Sep 2017 23:27:50 +0200 Subject: [PATCH] Percentage with fill level completed --- test/lcd_test.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/test/lcd_test.py b/test/lcd_test.py index a11b168..ca63855 100755 --- a/test/lcd_test.py +++ b/test/lcd_test.py @@ -41,13 +41,17 @@ maxVoltage = 3*4.2 # 3S LiPo-Battery with 3 x 4.2Volt = 12.6 Volt (full battery) -# -# test voltages -# -measuredVoltage = 12.4 -# percent +# ------------ +# test voltage +# ------------ +measuredVoltage = 11.25 + + +# percent calculation convertedVoltage = measuredVoltage - minVoltage percent = convertedVoltage / (maxVoltage-minVoltage) * 100 +if percent < 0: + percent = 0 # the battery symbols @@ -55,8 +59,9 @@ # battery level (white rectangle in empty battery symbol -rectLength=0 maxRectLength = 16 +rectLength = round(percent * maxRectLength / 100, 0) + # endless loop while (1): @@ -79,17 +84,17 @@ string = ("%.0f %%" % round(percent, 2)) draw.text((symbolWidth, 0), string, font=fontText, fill=255) # line 2 - draw.text((0, size), str(measuredVoltage) + ' Volt', font=fontText, fill=255) + draw.text((0, size), str("%.2f Volt" % measuredVoltage), font=fontText, fill=255) # Display image. disp.image(image) disp.display() # wait a bit - time.sleep(0.25) + time.sleep(0.5) # next time in this loop - if rectLength < maxRectLength: - rectLength = rectLength + 1 - else: - rectLength = 0 +# if rectLength < maxRectLength: +# rectLength = rectLength + 1 +# else: +# rectLength = 0