mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Add ADC.voltage property, fix #329
This commit is contained in:
@@ -72,11 +72,12 @@ class AnalogInputDevice(SPIDevice):
|
|||||||
.. _analog to digital converters: https://en.wikipedia.org/wiki/Analog-to-digital_converter
|
.. _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:
|
if bits is None:
|
||||||
raise InputDeviceError('you must specify the bit resolution of the device')
|
raise InputDeviceError('you must specify the bit resolution of the device')
|
||||||
self._bits = bits
|
self._bits = bits
|
||||||
super(AnalogInputDevice, self).__init__(shared=True, **spi_args)
|
super(AnalogInputDevice, self).__init__(shared=True, **spi_args)
|
||||||
|
self._max_voltage = max_voltage
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def bits(self):
|
def bits(self):
|
||||||
@@ -103,6 +104,13 @@ class AnalogInputDevice(SPIDevice):
|
|||||||
"""
|
"""
|
||||||
return self._read()
|
return self._read()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def voltage(self):
|
||||||
|
"""
|
||||||
|
The current voltage read from the device
|
||||||
|
"""
|
||||||
|
return self.value * self._max_voltage
|
||||||
|
|
||||||
|
|
||||||
class MCP3xxx(AnalogInputDevice):
|
class MCP3xxx(AnalogInputDevice):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user