api/nxtdevices: add VernierAdapter

This commit is contained in:
Laurens Valk
2020-02-12 12:49:40 +01:00
parent d1a9d6f15f
commit 57a44265b8
3 changed files with 64 additions and 1 deletions
+11
View File
@@ -54,3 +54,14 @@ NXT Temperature Sensor
NXT Energy Meter
^^^^^^^^^^^^^^^^^
.. autoclass:: pybricks.nxtdevices.EnergyMeter
Vernier Adapter
^^^^^^^^^^^^^^^^^
.. autoclass:: pybricks.nxtdevices.VernierAdapter
.. toggle-header::
:header: **Show/hide example**
**Example: Using the Surface Temperature Sensor.**
.. literalinclude:: ../../pybricks-projects/snippets/ev3/vernier_surface_temperature/main.py
+52
View File
@@ -1,6 +1,9 @@
"""Use LEGO® MINDSTORMS® NXT motors and sensors with the EV3 brick."""
from pybricks.iodevices import AnalogSensor
class TouchSensor():
"""LEGO® MINDSTORMS® NXT Touch Sensor."""
@@ -221,3 +224,52 @@ class EnergyMeter():
"""
pass
class VernierAdapter(AnalogSensor):
"""LEGO® MINDSTORMS® Education NXT/EV3 Adapter for Vernier Sensors."""
def __init__(self, port, conversion=None):
"""
Arguments:
port (Port): Port to which the sensor is connected.
conversion (callable): Function of the format :meth:`.conversion`.
This function is used to convert the raw analog voltage to the
sensor-specific output value. Each Vernier Sensor has its
own conversion function. The example given below demonstrates
the conversion for the Surface Temperature Sensor.
"""
pass
def voltage(self):
"""Measure the raw analog sensor voltage.
Returns:
:ref:`voltage`: Analog voltage.
"""
pass
def conversion(self, voltage):
"""User-supplied function that converts the raw voltage (mV) to a
sensor value.
If you did not provide a ``conversion`` function earlier, no conversion
will be applied.
Arguments:
voltage (:ref:`voltage`): Analog sensor voltage
:returns: Converted sensor value.
:rtype: float
"""
pass
def value(self):
"""This method measures the sensor :meth:`.voltage` and then
applies your :meth:`.conversion` to give you the sensor value.
:returns: Converted sensor value.
:rtype: float
"""
pass