From 08a52b13990e0e3d1764726dae84481072e3db4a Mon Sep 17 00:00:00 2001 From: yamenk-gribaudo <102967309+yamenk-gribaudo@users.noreply.github.com> Date: Sun, 2 Jul 2023 10:37:54 -0300 Subject: [PATCH 1/3] support leading ceros in number function --- tm1637.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tm1637.py b/tm1637.py index 0f601f3..ddd31c7 100644 --- a/tm1637.py +++ b/tm1637.py @@ -160,11 +160,14 @@ def hex(self, val): string = '{:04x}'.format(val & 0xffff) self.write(self.encode_string(string)) - def number(self, num): - """Display a numeric value -999 through 9999, right aligned.""" + def number(self, num, ceros=False): + """Display a numeric value -999 through 9999, right aligned or with leading ceros""" # limit to range -999 to 9999 num = max(-999, min(num, 9999)) - string = '{0: >4d}'.format(num) + if ceros: + string = "{:04d}".format(num) + else: + string = '{0:>4d}'.format(num) self.write(self.encode_string(string)) def numbers(self, num1, num2, colon=True): From d3c333646fa0e20ec77782dc6637227b51b60ed5 Mon Sep 17 00:00:00 2001 From: yamenk-gribaudo <102967309+yamenk-gribaudo@users.noreply.github.com> Date: Tue, 4 Jul 2023 17:32:07 -0300 Subject: [PATCH 2/3] Update tm1637.py --- tm1637.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tm1637.py b/tm1637.py index ddd31c7..db3160a 100644 --- a/tm1637.py +++ b/tm1637.py @@ -160,11 +160,11 @@ def hex(self, val): string = '{:04x}'.format(val & 0xffff) self.write(self.encode_string(string)) - def number(self, num, ceros=False): + def number(self, num, zeros=False): """Display a numeric value -999 through 9999, right aligned or with leading ceros""" # limit to range -999 to 9999 num = max(-999, min(num, 9999)) - if ceros: + if zeros: string = "{:04d}".format(num) else: string = '{0:>4d}'.format(num) From 40a2bafc0bccc4d608e979faf738f533aa26d50a Mon Sep 17 00:00:00 2001 From: yamenk-gribaudo <102967309+yamenk-gribaudo@users.noreply.github.com> Date: Tue, 4 Jul 2023 17:32:50 -0300 Subject: [PATCH 3/3] Update tm1637.py --- tm1637.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tm1637.py b/tm1637.py index db3160a..747090c 100644 --- a/tm1637.py +++ b/tm1637.py @@ -161,7 +161,7 @@ def hex(self, val): self.write(self.encode_string(string)) def number(self, num, zeros=False): - """Display a numeric value -999 through 9999, right aligned or with leading ceros""" + """Display a numeric value -999 through 9999, right aligned or with leading zeros""" # limit to range -999 to 9999 num = max(-999, min(num, 9999)) if zeros: