From 28f1d34ff9cdd8d54e9315a26ea5ee4e1ee8ea84 Mon Sep 17 00:00:00 2001 From: Ben Nuttall Date: Thu, 26 May 2016 17:32:37 +0100 Subject: [PATCH] Add ADC.voltage property, fix #329 --- gpiozero/spi_devices.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gpiozero/spi_devices.py b/gpiozero/spi_devices.py index 84cc8cc..60d9fa0 100644 --- a/gpiozero/spi_devices.py +++ b/gpiozero/spi_devices.py @@ -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): """