Add ADC.voltage property, fix #329

This commit is contained in:
Ben Nuttall
2016-05-26 17:32:37 +01:00
parent 9278a2f857
commit 28f1d34ff9

View File

@@ -72,11 +72,12 @@ class AnalogInputDevice(SPIDevice):
.. _analog to digital converters: https://en.wikipedia.org/wiki/Analog-to-digital_converter
"""
def __init__(self, bits=None, **spi_args):
def __init__(self, bits=None, max_voltage=3.3, **spi_args):
if bits is None:
raise InputDeviceError('you must specify the bit resolution of the device')
self._bits = bits
super(AnalogInputDevice, self).__init__(shared=True, **spi_args)
self._max_voltage = max_voltage
@property
def bits(self):
@@ -103,6 +104,13 @@ class AnalogInputDevice(SPIDevice):
"""
return self._read()
@property
def voltage(self):
"""
The current voltage read from the device
"""
return self.value * self._max_voltage
class MCP3xxx(AnalogInputDevice):
"""