Skip to content

Commit e89e726

Browse files
committed
Updating for MCP4728A4
Updating library to be able to pass 0x64 I2C address for MCP4728A4 variant
1 parent 99c8739 commit e89e726

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

adafruit_mcp4728.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class MCP4728:
115115
116116
"""
117117

118-
def __init__(self, i2c_bus, address=_MCP4728_DEFAULT_ADDRESS):
118+
def __init__(self, i2c_bus, address: int = _MCP4728_DEFAULT_ADDRESS):
119119

120120
self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
121121

@@ -289,7 +289,7 @@ def __init__(self, dac_instance, cache_page, index):
289289
@property
290290
def normalized_value(self):
291291
"""The DAC value as a floating point number in the range 0.0 to 1.0."""
292-
return self.raw_value / (2**12 - 1)
292+
return self.raw_value / (2 ** 12 - 1)
293293

294294
@normalized_value.setter
295295
def normalized_value(self, value):
@@ -302,13 +302,13 @@ def normalized_value(self, value):
302302
def value(self):
303303
"""The 16-bit scaled current value for the channel. Note that the MCP4728 is a 12-bit piece
304304
so quantization errors will occur"""
305-
return self.normalized_value * (2**16 - 1)
305+
return self.normalized_value * (2 ** 16 - 1)
306306

307307
@value.setter
308308
def value(self, value):
309-
if value < 0 or value > (2**16 - 1):
309+
if value < 0 or value > (2 ** 16 - 1):
310310
raise AttributeError(
311-
"`value` must be a 16-bit integer between 0 and %s" % (2**16 - 1)
311+
"`value` must be a 16-bit integer between 0 and %s" % (2 ** 16 - 1)
312312
)
313313

314314
# Scale from 16-bit to 12-bit value (quantization errors will occur!).
@@ -321,9 +321,9 @@ def raw_value(self):
321321

322322
@raw_value.setter
323323
def raw_value(self, value):
324-
if value < 0 or value > (2**12 - 1):
324+
if value < 0 or value > (2 ** 12 - 1):
325325
raise AttributeError(
326-
"`raw_value` must be a 12-bit integer between 0 and %s" % (2**12 - 1)
326+
"`raw_value` must be a 12-bit integer between 0 and %s" % (2 ** 12 - 1)
327327
)
328328
self._raw_value = value
329329
# disabling the protected access warning here because making it public would be

0 commit comments

Comments
 (0)