@@ -47,8 +47,9 @@ class HT16K33:
4747 :param int address: The I2C addess of the HT16K33.
4848 :param bool auto_write: True if the display should immediately change when
4949 set. If False, `show` must be called explicitly.
50+ :param float brightness: 0.0 - 1.0 default brightness level.
5051 """
51- def __init__ (self , i2c , address = 0x70 , auto_write = True ):
52+ def __init__ (self , i2c , address = 0x70 , auto_write = True , brightness = 1.0 ):
5253 self .i2c_device = i2c_device .I2CDevice (i2c , address )
5354 self ._temp = bytearray (1 )
5455 self ._buffer = bytearray (17 )
@@ -58,7 +59,7 @@ def __init__(self, i2c, address=0x70, auto_write=True):
5859 self ._blink_rate = None
5960 self ._brightness = None
6061 self .blink_rate = 0
61- self .brightness = 15
62+ self .brightness = brightness
6263
6364 def _write_cmd (self , byte ):
6465 self ._temp [0 ] = byte
@@ -81,16 +82,18 @@ def blink_rate(self, rate=None):
8182
8283 @property
8384 def brightness (self ):
84- """The brightness. Range 0-15. """
85+ """The brightness. Range 0.0-1.0 """
8586 return self ._brightness
8687
8788 @brightness .setter
8889 def brightness (self , brightness ):
89- if not 0 <= brightness <= 15 :
90- raise ValueError ('Brightness must be an integer in the range: 0-15 ' )
91- brightness = brightness & 0x0F
90+ if not 0.0 <= brightness <= 1.0 :
91+ raise ValueError ('Brightness must be a decimal number in the range: 0.0-1.0 ' )
92+
9293 self ._brightness = brightness
93- self ._write_cmd (_HT16K33_CMD_BRIGHTNESS | brightness )
94+ xbright = round (15 * brightness )
95+ xbright = xbright & 0x0F
96+ self ._write_cmd (_HT16K33_CMD_BRIGHTNESS | xbright )
9497
9598 @property
9699 def auto_write (self ):
0 commit comments