From 55fe666dac9619bdb819a2b7f35d91f4ae64ce7e Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Wed, 1 Jul 2020 12:02:13 +0200 Subject: [PATCH] api/pupdevices: add InfraredSensor --- doc/api/pupdevices.rst | 16 ++++++++++++++++ pybricks/pupdevices.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/doc/api/pupdevices.rst b/doc/api/pupdevices.rst index 0cb5bc3..3e1bae1 100644 --- a/doc/api/pupdevices.rst +++ b/doc/api/pupdevices.rst @@ -189,6 +189,22 @@ Force Sensor .. automethod:: pybricks.pupdevices.ForceSensor.touched +Infrared Sensor +^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. figure:: ../api/images/sensor_proximity.png + :width: 35 % + +.. autoclass:: pybricks.pupdevices.InfraredSensor + :no-members: + + .. automethod:: pybricks.pupdevices.InfraredSensor.distance + + .. automethod:: pybricks.pupdevices.InfraredSensor.reflection + + .. automethod:: pybricks.pupdevices.InfraredSensor.count + + .. Tilt Sensor .. ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/pybricks/pupdevices.py b/pybricks/pupdevices.py index 2851f40..4f296bc 100644 --- a/pybricks/pupdevices.py +++ b/pybricks/pupdevices.py @@ -313,6 +313,45 @@ class ForceSensor: pass +class InfraredSensor: + """LEGO® Powered Up Infrared Sensor.""" + + def __init__(self, port): + """ + + Arguments: + port (Port): Port to which the sensor is connected. + """ + pass + + def reflection(self): + """Measures the reflection of a surface using an infrared light. + + Returns: + :ref:`percentage`: Reflection, ranging from 0.0 (no reflection) to + 100.0 (high reflection). + """ + pass + + def distance(self): + """Measures the relative distance between the sensor and an object + using infrared light. + + Returns: + :ref:`relativedistance`: Relative distance ranging from 0 (closest) + to 100 (farthest). + """ + pass + + def count(self): + """Counts the number of objects that have passed by the sensor. + + Returns: + int: Number of objects counted. + """ + pass + + class Light(_Light): """LEGO® Powered Up Light."""