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
|
||||
"""
|
||||
|
||||
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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user