diff --git a/tm1637.py b/tm1637.py index 2da7d3a..51314d6 100644 --- a/tm1637.py +++ b/tm1637.py @@ -1,3 +1,6 @@ +# MicroPython TM1637 quad 7-segment LED display driver + +from machine import Pin from time import sleep_us _CMD_SET1 = const(64) # 0x40 data set @@ -18,21 +21,21 @@ def __init__(self, clk, dio, brightness=7): raise ValueError("Brightness out of range") self._brightness = brightness - self.clk.init(clk.IN) - self.dio.init(dio.IN) - self.clk.low() - self.dio.low() + self.clk.init(Pin.IN) + self.dio.init(Pin.IN) + self.clk(0) + self.dio(0) def _start(self): - self.dio.init(self.dio.OUT) + self.dio.init(Pin.OUT) sleep_us(50) def _stop(self): - self.dio.init(self.dio.OUT) + self.dio.init(Pin.OUT) sleep_us(50) - self.clk.init(self.clk.IN) + self.clk.init(Pin.IN) sleep_us(50) - self.dio.init(self.dio.IN) + self.dio.init(Pin.IN) sleep_us(50) def _write_comm1(self): @@ -48,18 +51,18 @@ def _write_comm3(self): def _write_byte(self, b): # send each bit for i in range(8): - self.clk.init(self.clk.OUT) + self.clk.init(Pin.OUT) sleep_us(50) - self.dio.init(self.dio.IN if b & 1 else self.dio.OUT) + self.dio.init(Pin.IN if b & 1 else Pin.OUT) sleep_us(50) - self.clk.init(self.clk.IN) + self.clk.init(Pin.IN) sleep_us(50) b >>= 1 - self.clk.init(self.clk.OUT) + self.clk.init(Pin.OUT) sleep_us(50) - self.clk.init(self.clk.IN) + self.clk.init(Pin.IN) sleep_us(50) - self.clk.init(self.clk.OUT) + self.clk.init(Pin.OUT) sleep_us(50) def brightness(self, val=None): diff --git a/tm1637_test.py b/tm1637_test.py index db0a93a..c2bc959 100644 --- a/tm1637_test.py +++ b/tm1637_test.py @@ -1,3 +1,5 @@ +# MicroPython TM1637 quad 7-segment LED display driver examples + # WeMos D1 Mini -- 4 Digit Display # D1 (GPIO5) ----- CLK # D2 (GPIO4) ----- DIO @@ -146,3 +148,6 @@ # show "12:59" tm.numbers(12,59) + +# show temperature +tm.temperature(24) '24*C' \ No newline at end of file