@@ -47,8 +47,9 @@ class HT16K33:
47
47
:param int address: The I2C addess of the HT16K33.
48
48
:param bool auto_write: True if the display should immediately change when
49
49
set. If False, `show` must be called explicitly.
50
+ :param float brightness: 0.0 - 1.0 default brightness level.
50
51
"""
51
- def __init__ (self , i2c , address = 0x70 , auto_write = True ):
52
+ def __init__ (self , i2c , address = 0x70 , auto_write = True , brightness = 1.0 ):
52
53
self .i2c_device = i2c_device .I2CDevice (i2c , address )
53
54
self ._temp = bytearray (1 )
54
55
self ._buffer = bytearray (17 )
@@ -58,7 +59,7 @@ def __init__(self, i2c, address=0x70, auto_write=True):
58
59
self ._blink_rate = None
59
60
self ._brightness = None
60
61
self .blink_rate = 0
61
- self .brightness = 15
62
+ self .brightness = brightness
62
63
63
64
def _write_cmd (self , byte ):
64
65
self ._temp [0 ] = byte
@@ -81,16 +82,18 @@ def blink_rate(self, rate=None):
81
82
82
83
@property
83
84
def brightness (self ):
84
- """The brightness. Range 0-15. """
85
+ """The brightness. Range 0.0-1.0 """
85
86
return self ._brightness
86
87
87
88
@brightness .setter
88
89
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
+
92
93
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 )
94
97
95
98
@property
96
99
def auto_write (self ):
0 commit comments